forked from thirdbridge/git-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reset.sh
executable file
·52 lines (39 loc) · 1.27 KB
/
reset.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
#!/bin/bash
git fetch --all
git checkout -b tempxyz
source_raw=$(git branch -r | grep 'source/')
origin_raw=$(git branch -r | grep 'origin/' | grep -v 'HEAD')
local_raw=$(git branch | grep -v 'tempxyz')
source_array=()
origin_array=()
local_array=()
while IFS= read -r line; do
branch_name=$(echo $line | sed 's/^[^\/]*\///')
source_array+=("$branch_name")
done <<< "$source_raw"
while IFS= read -r line; do
branch_name=$(echo $line | sed 's/^[^\/]*\///')
origin_array+=("$branch_name")
done <<< "$origin_raw"
while IFS= read -r line; do
local_array+=("$line")
done <<< "$local_raw"
remote_diff_array=($(comm -13 <(printf "%s\n" "${source_array[@]}" | sort) <(printf "%s\n" "${origin_array[@]}" | sort)))
local_diff_array=($(comm -13 <(printf "%s\n" "${source_array[@]}" | sort) <(printf "%s\n" "${local_array[@]}" | sort)))
echo "${local_diff_array[@]}"
for branch in "${source_array[@]}"; do
git branch -f $branch source/$branch
git branch $branch -u origin/$branch
git push -f origin $branch
done
for branch in "${remote_diff_array[@]}"; do
git push --delete origin $branch
done
for branch in "${local_diff_array[@]}"; do
git branch -D $branch
done
git checkout -- .
git branch -f main origin/main
git branch main -u origin
git checkout main
git branch -D tempxyz