Skip to content

Commit 920f07b

Browse files
committed
Shortcut for pushing and tracking current branch
1 parent 1292ab4 commit 920f07b

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ Commands
2727
* `git merge-branch` - Pull-Request Merge current Branch to Master
2828
* `git create-pr` - Shortcut to push branch and create a pull-request
2929
30+
Helpful Aliases
31+
---------------
32+
Add the following aliases to `.bashrc`, `.bash_profile`, or `.zshrc`
33+
34+
```sh
35+
alias pr="git create-pr"
36+
alias push="git push-branch"
37+
alias merge="git merge-branch"
38+
alias pr-merge="git merge-pr"
39+
```
40+
41+
3042
Contributors
3143
------------
3244

git-push-branch

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
function usage() {
6+
bold=$(tput bold)
7+
normal=$(tput sgr0)
8+
cat << EOF
9+
10+
${bold}NAME${normal}
11+
git-push-branch - Push the current branch and track remote
12+
13+
${bold}SYNOPSIS${normal}
14+
git push-branch
15+
16+
EOF
17+
}
18+
19+
# actually parse the options and do stuff
20+
while [[ $1 = -?* ]]; do
21+
case $1 in
22+
-h|--help)
23+
usage
24+
exit 0
25+
;;
26+
*) ;;
27+
esac
28+
shift
29+
done
30+
31+
branch=$(git rev-parse --abbrev-ref HEAD)
32+
upstream=$(git rev-parse --abbrev-ref @{upstream} 2>/dev/null)
33+
34+
if [[ $? == 0 ]]; then
35+
echo "branch '$branch' tracks '$upstream'"
36+
git push
37+
else
38+
echo "branch '$branch' has no upstream configured"
39+
git push -u origin $branch
40+
fi
41+
42+

0 commit comments

Comments
 (0)