0 votes
1 view
in Devops and Agile by (20k 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 (28.4k points)

In order to control the default behavior, try setting push.default in your git config. 

push.default

This will define the action git push should take, if 

A. No refspec is given on the command line, 

B. No refspec is configured in the remote, and 

C. No refspec is implied by any of the options given on the command line. 

Let us talk about the possible values:

nothing: Do not push anything

matching: Push all matching branches

Note that, branches with the same name in both ends are considered to be matching. .

upstream: This pushed the current branch to its upstream branch

current: This pushs the current branch to a branch of the same name

simple: Just like upstream, but refuses to push if the upstream branch's name is different from the local one

This is the safest option and is well-suited for beginners.

These 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. 

Here are two command line examples:

In order to have a look at the current configuration use the following:

$ git config --global push.default

In order to set a new configuration use the following command:

$ git config --global push.default current

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...