-
Notifications
You must be signed in to change notification settings - Fork 2
/
git-merge-um
executable file
·55 lines (48 loc) · 2 KB
/
git-merge-um
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
#!/bin/sh
### This Git method script pulls all new commits, branches and tags from
### an upstream repo (reference can be picked with "-R otherrepo"), and
### updates your currently checked out branch with that upstream's "master"
### branch (can be picked with "-B otherbranch"; see also branch-alias for
### permament branch-name re-mappings). Optionally (-r) you can also rebase
### the resulting current branch vs. the remote "upstream/master" so your
### added work ends up as clean top-commits and no "merge" commits arise
### in your own history (note that this may require you to `git push -f`
### and you should NOT do this in shared repositories that anyone else
### pulls from - but it is common practice to do so in private forks while
### preparing a pull request).
### Finally sync the result back to default target repo (usually "origin" -
### depends on "--set-upstream-to" configuration of your branch).
### Copyright (C) 2015-2016 by Jim Klimov, License: MIT
do_git_merge_update_master() {
BASE_REPO=upstream
BASE_BRANCH=master
DO_REBASE=no
while [ "$#" -gt 0 ]; do
case "$1" in
-BR) BASE_REPO="$2"; shift ;;
-BB) BASE_BRANCH="$2"; shift ;;
-r) DO_REBASE=yes ;;
*) echo "FATAL: Unknown argument: '$1'" >&2; return 1 ;;
esac
shift
done
CUR_BRANCH="`git branch | egrep '^\*' | sed 's,^\* ,,'`"
echo "=== $0 in repo `pwd` branch ${CUR_BRANCH} ..."
echo "=== Syncing from all remotes ..."
git pull --all
git pull --tags
git pull "${BASE_REPO}"
echo ""
echo "=== Merging from repo ${BASE_REPO}/${BASE_BRANCH} into repo `pwd` branch ${CUR_BRANCH} ..."
git merge "${BASE_REPO}/${BASE_BRANCH}" || exit
if [ "$DO_REBASE" = yes ] ; then
echo ""
echo "=== Rebasing from repo ${BASE_REPO}/${BASE_BRANCH} into repo `pwd` branch ${CUR_BRANCH} ..."
git rebase -i "${BASE_REPO}/${BASE_BRANCH}" || exit
echo "=== NOTE: You may need to 'git push -f' to actually publish your changes"
fi
echo ""
echo "=== Pushing the changes back..."
git sync
}
do_git_merge_update_master "$@"