I\'d like to improve my current aliases, most of them work over a branch. Is there a way to refer to the current branch in a git alias so I don\'t need to pass it each time?
[alias]
po = "!git push --set-upstream origin \"$(git rev-parse --abbrev-ref HEAD)\""
This answer will be valid starting from Git 2.0, where the default push behaviour will be simple
Unless push.default
setting is set to matching
, git push
without specifying argument will always push the current branch, so in this case you don't need to specify it.
It's not 100% clear from your question which of these two aliases you require.
This will push the currently checked out branch:
git config alias.po !f() { export tmp_branch=`git branch | grep '* ' | tr -d '* '` && git push origin $tmp_branch; unset $tmp_branch; }; f
This will push a given branch name (git po branchName
):
git config alias.po !f() { git push origin $1; }; f
git symbolic-ref --short HEAD
prints the current branch, so you can define a simple shell alias:
alias gpo='git push origin "$(git symbolic-ref --short HEAD)"'