How do you push just a single Git branch (and no other branches)?
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 (i.e. central workflow). No need to have the same name for local and remote branch.tracking
: Deprecated, useupstream
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 likeupstream
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 ascurrent
. This is the safest option and is suited for beginners. This mode has become the default in Git 2.0.
yes, just do the following
git checkout feature_x
git push origin feature_x
Minor update on top of Karthik Bose's answer - you can configure git globally, to affect all of your workspaces to behave that way:
git config --global push.default upstream