Search code examples
gitgit-push

Understanding git push command


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?


Solution

  • 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