push current branch shortcut

Is there a shortcut to tell Git to push the current tracking branch to origin?
Note: I know that I can change the default push behavior, but I am looking for an ad-hoc solution that does not change the default behavior.

For example, suppose I am on branch feature/123-sandbox-tests I would be using

git push origin feature/123-sandbox-tests

which is tedious. I am looking for a shortcut, something like

git push origin current

where git knows that current is feature/123-sandbox-tests .


Edit : Starting from version 2.0, git's default behavior has changed to a more intuitive behavior, which is what I wanted to achieve. See This SO question for details.

Edit 2 : ceztko's answer is the best answer as it allows to push the current branch, regardless of the settings.


According to git push documentation:

git push origin HEAD
    A handy way to push the current branch to the same name on the remote.

So I think what you need is git push origin HEAD . Also it can be useful git push -u origin HEAD to set upstream tracking information in the local branch, if you haven't already pushed to the origin.


You can configure git to push to the current branch using the following command

git config --global push.default current

then just do

git push 

this will push the code to your current branch.


You should take a look to a similar question in Default behavior of "git push" without a branch specified

Basically it explains how to set the default behavior to push your current branch just executing git push . Probably what you need is:

git config --global push.default current

Other options:

  • nothing : Do not push anything
  • matching : Push all matching branches
  • upstream / tracking : Push the current branch to whatever it is tracking
  • current : Push the current branch
  • 链接地址: http://www.djcxy.com/p/4544.html

    上一篇: 为什么叫git分支

    下一篇: 推送当前分支快捷键