forked from stephenh/git-central
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpull
executable file
·33 lines (29 loc) · 1 KB
/
pull
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/bash
#
# Makes pull "just work" by correctly rebasing of local commits on top of new
# incoming commits.
#
# This avoids the "same-branch" merges that the default "git pull" creates of
# your local branch foo being merged into the remote branch origin/foo.
#
# Also, even though "git pull" has a branch.<name>.rebase flag, it will replay
# commits if you have local merges of other branches that are being rebased--the
# "-p" parameter to git rebase prevents this reply but is not available from the
# "git pull" command line or config options--hence this script.
#
branch_name=$(git symbolic-ref --quiet HEAD)
if [[ $? -ne 0 ]] ; then
echo "Not on a branch"
exit 1
fi
branch_name=${branch_name/refs\/heads\//}
git fetch
if [[ $? -ne 0 ]] ; then
exit $?
fi
# rebase-p-i stops if nothing to do, even a ff, so do a non-i-p if needed
if test "$(git rev-parse HEAD)" = "$(git merge-base HEAD origin/$branch_name)" ; then
git rebase "origin/$branch_name"
else
GIT_EDITOR=: git rebase -p -i "origin/$branch_name"
fi