-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-rewind
executable file
·58 lines (49 loc) · 1.44 KB
/
git-rewind
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
#!/bin/bash
set -e # kill script ASAP if any command returns non-true
INITIALS=mf
if [[ ! -d .git ]]; then
echo 'OI! Run from a place that has a .git directory on it!'
exit 1
fi
trap 'echo AIEE; exit 1' EXIT
# A development branch "child" contains the parent branch name, separated
# by double dashes
REGEX_DEVELOPMENT_BRANCH='^(.*)--(.*)$'
git stash
### Just "git fa && git prom" instead.
git fetch --verbose origin
git checkout master
git pull --rebase origin master
# TLC for the "mf/work" branch
echo "Rebasing special $INITIALS/work branch from master"
git checkout $INITIALS/work
git rebase master $*
git checkout master
for mybra in $(git branch | grep -e " $INITIALS/" | grep -v '^$'); do
echo
if [[ $mybra =~ $REGEX_DEVELOPMENT_BRANCH ]]; then
PARENTDEV=${BASH_REMATCH[1]}
echo "Rebasing $mybra to PARENT '$PARENTDEV'"
git checkout $mybra
git rebase $PARENTDEV $*
if [[ -z $1 ]]; then # not when interactively
git push origin +$mybra
fi
else
if [[ $mybra =~ 'dev-' ]]; then
echo "Rebasing $mybra to WORK"
git checkout $mybra
git rebase $INITIALS/work $*
else
echo "Rebasing $mybra to MASTER"
git checkout $mybra
git rebase master $*
if [[ -z $1 ]]; then # not when interactively
git push origin +$mybra
fi
fi
fi
done
echo
trap - EXIT
exit 0