-
Notifications
You must be signed in to change notification settings - Fork 3
/
git-pushme
executable file
·64 lines (53 loc) · 1.32 KB
/
git-pushme
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
59
60
61
62
63
64
#!/bin/bash
#
# This will push the branch you're currently in to the remote that it's
# tracking, if there is one. This avoids having to correctly type the current
# branch name, but gives you the benefit of not accidentally pushing
# branches that aren't ready.
#
function usage() {
echo "Usage: git pushme [-f | --force] [commit]" >&2
}
force=""
GETOPT=$(getopt -u -o hf --long force -- "$@")
if [[ $? != 0 ]]; then
usage
exit 1
fi
set -- $GETOPT
while [[ 0 != $# ]]; do
case "$1" in
-f|--force)
force="-f"
;;
-h)
usage
exit 0
;;
--)
shift
break
;;
*)
echo "Unrecognized option ($1)??" >&2
usage
exit 1
;;
esac
shift
done
ref=$(git symbolic-ref HEAD 2>/dev/null)
branch=${ref##refs/heads/}
if [[ -z $branch ]]; then
echo "Not on any branch that I can find!"
exit 1
fi
remote=$(git config --get "branch.$branch.remote")
# Allow the user to specify a SHA that's not at the tip. If they
# make a mistake here, they should get a non fast-forward error.
where=${1:+"$1:"}
if [[ -z $remote ]]; then
echo 'Your branch is not tracking a remote branch. Consider using "git corb"'
exit 1
fi
git push $force $remote $where$branch