Sunday, September 14, 2014

The default behavior of 'git push'...

Whenever we decide to share our work, we do push our changes to a remote repository.
If you are working only in a single branch then you don't need to worry about this topic. But if you have many branches, you must aware the default behavior of 'git push'. This command actually pushes all branches (not only your current branch) to the corresponding remote branches.
But, mostly we want to push only the current branch to the remote repo. We can configure GIT to change the default behavior.
git config push.default upstream
It means git will update only the current branch to it's upstream, when you do git push.
Other valid options are:
nothing : Do not push anything.
matching : Push all matching branches (default).
upstream: Push the current branch to its upstream branch. (the branch git pull would pull from)
tracking : Deprecated, use upstream instead.
current : Push the current branch to the remote branch of the same name.

UPDATE:

Since git version 1.7.11, A new mode, "simple", which is a cross between "current" and "upstream", has been introduced. "git push" without any refspec will push the current branch to the remote branch with the same name, only when it is set to track the remote branch. This mode is the new default value when push.default is not configured.