How do you push just a single Git branch (and no other branches)?

I am working on a local git repository. There are two branches, master and feature_x .

I want to push feature_x to the remote repo, but I do not want to push the changes on the master branch.

Will a git push origin feature_x from my feature_x branch ( feature_x branch already exists on remote) work?

I do not want to test this on my box, because I cannot push to master right now.



By default git push updates all the remote branches. But you can configure git to update only the current branch to it's upstream.

git config push.default upstream

It means git will update only the current (checked out) branch when you do git push.

Other valid options are:

  • nothing : Do not push anything (error out) unless a refspec is explicitly given . This is primarily meant for people who want to avoid mistakes by always being explicit.
  • matching : Push all branches having the same name on both ends. (default option prior to Ver 1.7.11)
  • upstream : Push the current branch to its upstream branch. This mode only makes sense if you are pushing to the same repository you would normally pull from (ie central workflow ). No need to have the same name for local and remote branch.
  • tracking : Deprecated, use upstream instead.
  • current : Push the current branch to the remote branch of the same name on the receiving end. Works in both central and non-central workflows.
  • simple : [available since Ver 1.7.11] in centralized workflow, work like upstream with an added safety to refuse to push if the upstream branch's name is different from the local one. When pushing to a remote that is different from the remote you normally pull from, work as current . This is the safest option and is suited for beginners. This mode has become the default in Git 2.0.

  • 在Karthik Bose的答案之上稍作更新 - 您可以在全局配置git来影响您的所有工作空间,使其行为如此:

    git config --global push.default upstream
    
    链接地址: http://www.djcxy.com/p/26814.html

    上一篇: 如何将本地Git分支推送到远程的主分支?

    下一篇: 你如何推动一个Git分支(而不是其他分支)?