Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding git push command

Tags:

git

git-push

I am trying to understand one git command.

In my local repository, I'm currently on master.

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

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

git push review

Does it pushes changes to review branch on the same remote? Or does it pushes changes to another remote with the name review?

like image 712
Patan Avatar asked Sep 18 '14 13:09

Patan


People also ask

How do I push a git repository?

To push the commit from the local repo to your remote repositories, run git push -u remote-name branch-name where remote-name is the nickname the local repo uses for the remote repositories and branch-name is the name of the branch to push to the repository. You only have to use the -u option the first time you push.

What does the U in git push mean?

-u : The -u flag creates a tracking reference for every branch that you successfully push onto the remote repository. The local branch you push is automatically linked with the remote branch. This allows you to use commands such as git pull without any arguments.

What is git push and pull command?

git pull is one of many commands that claim the responsibility of 'syncing' remote content. The git remote command is used to specify what remote endpoints the syncing commands will operate on. The git push command is used to upload content to a remote repository.


1 Answers

I understand how this can be confusing. You would do well to choose distinct names for your branches and remotes.

When running git push review, you're essentially using the following syntax

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

but you're leaving the optional <refspec>... argument out. Therefore, here, git push understands review as a remote, not as a branch. So git push review will be pushing changes (if not everything is up-to-date) to your remote called review.

How will those changes get pushed? Here is a relevant passage of the git-push man page:

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 run git push review depends on your Git configuration. Run

git config remote.review.push

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

git config push.default

to see which mode push.default is currently in. For more details on what push.default does, I refer you to Default behavior of "git push" without a branch specified

like image 178
jub0bs Avatar answered Oct 20 '22 20:10

jub0bs