-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgit-rebase-all-branches
More file actions
executable file
·32 lines (29 loc) · 1.36 KB
/
git-rebase-all-branches
File metadata and controls
executable file
·32 lines (29 loc) · 1.36 KB
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
#!/bin/sh
# Check if a rebase is already in progress
if [ -d .git/rebase-merge ] || [ -d .git/rebase-apply ]; then
echo "Rebase in progress detected. Continuing rebase..."
if ! GIT_EDITOR=true git rebase --continue; then
echo "Failed to continue rebase. Please resolve conflicts and run this script again."
exit 1
fi
fi
# maybe the whole logic about default_rebase_target can be replaced by '@',
# see https://stackoverflow.com/a/66153331/22022448
#if git branch -a | grep -q 'gerrit/\(master\|main\)'; then
# default_rebase_target=gerrit
#else
# default_rebase_target=origin
#fi
#git symbolic-ref refs/remotes/$default_rebase_target/HEAD >/dev/null 2>&1 || git remote set-head origin --auto
#rebase_target="${rebase_target:-${1:-"$(git symbolic-ref refs/remotes/$default_rebase_target/HEAD | sed "s@^refs/remotes/default_rebase_target/@@")"}}"
rebase_target=${rebase_target:-$(git branch -a | grep 'origin/\(master\|main\)' | tail -n1)}
for i in $(git branch-raw | grep -v no_rebase) ; do
# Skip branches already up to date with rebase target
#shellcheck disable=SC2086
if git merge-base --is-ancestor $rebase_target "$i" 2>/dev/null; then
echo "Skipping $i (already up to date)"
continue
fi
#shellcheck disable=SC2086 disable=SC2015
git checkout "$i" && git rebase --rerere-autoupdate $rebase_target || break
done