Posted about 10 years ago. Visible to the public. Repeats.

Git: How to configure git to push only your current branch

You can change which branches will be pushed when saying git push. Our recommendation is to set it to current.

From the git-config documentation Archive :

: ^
Defines the action git push should take if no refspec is given on the command line, no refspec is configured in the remote, and no refspec is implied by any of the options given on the command line. Possible values are:

  • nothing - do not push anything.
  • matching - push all matching branches. All branches having the same name in both ends are considered to be matching. This is the default.
  • upstream - push the current branch to its upstream branch.
  • tracking - deprecated synonym for upstream.
  • current - push the current branch to a branch of the same name.

If you want to check your setting, do the following. By default, it will return matching (see above).

$ git config --global push.default matching

So to change that to push only current branches, just go ahead and say:

git config --global push.default current

Mind that omitting the --global flag only changes it for the current repository. Since it's hard to remember which project behaves how, you should find a suitable global setting.

Regardless which option you use you can manually do a git push origin my-branch to explicitly push only your current branch.

Caveat with current

For most of us, current is the safest push behavior. However, it has a small side effect: When a branch with your local name does not exist on your remote, it automatically creates it on the remote.

While that is usually what you want, it does not setup tracking between your local and remote branches. That means git pull won't work, and Git won't notify you when your local and remote branches differ.

To create a branch with the same name on the remote and setup tracking, use the -u option:

git push -u

You can also run git push -u another time if you accidentally created a remote branch, but forgot to setup tracking. If you can't currently push, use git branch --set-upstream-to=origin/$(git branch --show-current).

Does your version of Ruby on Rails still receive security updates?
Rails LTS provides security patches for unsupported versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2).

Owner of this card:

Arne Hartherz
Last edit:
about 1 year ago
by Michael Leimstädtner
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Arne Hartherz to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more