Push default

We already talked about the git push command and its default behavior. To avoid annoying issues, it is good practice to set a more convenient default behavior for this command.

There are two ways we can do this. First one: set Git to ask us the name of the branch we want to push every time, so a simple git push will have no effect. To obtain this, set push.default to nothing:

[1] ~/grocery-cloned (master) 
$ git config --global push.default nothing 
 
[2] ~/grocery-cloned (master) 
$ git push 
fatal: You didn't specify any refspecs to push, and push.default is "nothing". 

As you can see, now Git pretends that you specify the target branch at every push.

This is maybe too restrictive, but at least you can avoid common mistakes such as pushing some personal local branches to the remote, thus generating confusion in the team.

Another way to save yourself from this kind of mistake is to set the push.default parameter to simple, allowing Git to push only when there is a remote branch with the same name as the local one:

[3] ~/grocery-cloned (master) 
$ git config --global push.default simple 
 
[4] ~/grocery-cloned (master) 
$ git push 
Everything up-to-date 

This will push the local tracked branch to the remote.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.161.116