-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync_branch.sh
60 lines (53 loc) · 1.74 KB
/
sync_branch.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
# Exit on any error
set -e
set -x # Enable debugging output
branch=$1
if [ -z "$branch" ]; then
echo "Error: Branch name is not provided"
exit 1
fi
# Checkout the branch
echo "Checking out branch $branch..."
git checkout -b $branch main || git checkout $branch
# Merge changes from GitHub to GitLab
echo "Merging changes from GitHub to GitLab for branch $branch..."
if git pull github "$branch"; then
echo "Pulled changes from GitHub for branch $branch successfully."
else
echo "Failed to pull changes from GitHub for branch $branch."
fi
if git push gitlab "$branch"; then
echo "Pushed changes to GitLab for branch $branch successfully."
else
echo "Failed to push changes to GitLab for branch $branch."
fi
# Merge changes from GitLab to GitHub
echo "Merging changes from GitLab to GitHub for branch $branch..."
if git pull gitlab "$branch"; then
echo "Pulled changes from GitLab for branch $branch successfully."
else
echo "Failed to pull changes from GitLab for branch $branch."
fi
if git push github "$branch"; then
echo "Pushed changes to GitHub for branch $branch successfully."
else
echo "Failed to push changes to GitHub for branch $branch."
fi
# Handle conflicts if any
echo "Handling conflicts for branch $branch (if any)..."
if git merge --strategy-option theirs; then
echo "Merged conflicts for branch $branch using 'theirs' strategy."
else
echo "No conflicts to merge for branch $branch or merge failed."
fi
if git push github "$branch"; then
echo "Final push to GitHub for branch $branch successful."
else
echo "Final push to GitHub for branch $branch failed."
fi
if git push gitlab "$branch"; then
echo "Final push to GitLab for branch $branch successful."
else
echo "Final push to GitLab for branch $branch failed."
fi