Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.4k points)

I use the following command to push to my remote branch:

git push origin sandbox

If I say

git push origin

does that push changes in my other branches too, or does it only update my current branch? I have three branches: master, production, and sandbox.

The git push documentation is not very clear about this, so I'd like to clarify this for good.

Which branches and remotes do the following git push commands update exactly?

git push 

git push origin

origin above is remote.

I understand that git push [remote] [branch] will push only that branch to the remote.

1 Answer

0 votes
by (27.5k points)

In order to control the default behavior, set push.default in your git config: 

push.default

What it does? Well, it indicates git that the action git push should take place 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. 

Some of the possible values:

  • 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 used to be the default, but not since Git 2.0 (simple is the new default).

  • Upstream: push the current branch to its upstream branch (tracking is a deprecated synonym for upstream)
  • Current: push the current branch to a branch of the same name
  • Simple: (new in Git 1.7.11) like upstream, but refuses to push if the upstream branch's name is different from the local one. This can be considered as the safest option and is well-suited for beginners. This mode is made default in Git 2.0.

Also, note that the simple, current and upstream modes are for those who want to push out a single branch after finishing work, even when the other branches are not yet ready to be pushed out

Command line examples:

In order to view the current configuration:

$ git config --global push.default

In order to set a new configuration:

$ git config --global push.default current

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...