Understanding the git push command

I am trying to understand one git command.

In my local repository, I am now at master .

I'm on a remote phone named origin , in which two branches live: master and review . However, I have another remote, also called review ...

My question is: what happens when I run the following command?

 git push review 

Does it push changes to the review branch on the same remote? Or is he pushing the changes to another remote called review ?

+5
source share
2 answers

I understand how this can be confusing. It would be nice for you to choose different names for your branches and consoles.

When you run git push review you essentially use the following syntax

 git push <repository> [<refspec>...] 

but you leave the optional argument <refspec>... Therefore, here git push understands review as remote and not as a branch. Thus, git push review will push the changes (if not all relevant) to your remote called review .

How will these changes be carried forward? Here is the relevant git-push page breakaway:

 When the command line does not specify what to push with <refspec>... arguments or --all, --mirror, --tags options, the command finds the default <refspec> by consulting remote.*.push configuration, and if it is not found, honors push.default configuration to decide what to push (See gitlink:git-config[1] for the meaning of push.default). 

So what happens when you start git push review depends on your Git configuration. Run

 git config remote.review.push 

If a match is found, then the corresponding value determines what happens when git push review starts. If no match is found, Git uses the value of push.default to figure out what to do; run

 git config push.default 

to find out what mode push.default is push.default . For more information on what push.default does, I refer you to the default behavior of "git push" without specifying a branch

+4
source

You can see the documentation.

http://git-scm.com/docs/git-push

 [<repository> [<refspec>...]] 

First repository , and then branch. But if you do not specify the branch name, it takes the same branch name that you actually wrote out.

0
source

Source: https://habr.com/ru/post/1202879/


All Articles