8

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?

jub0bs
  • 60,866
  • 25
  • 183
  • 186
Patan
  • 17,073
  • 36
  • 124
  • 198
  • What you mean by *I'm on Origin remote* is unclear. Your local repository may list other repositories as its "remotes", but "being on a remote" doesn't make sense. – jub0bs Sep 18 '14 at 13:53

2 Answers2

6

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

Community
  • 1
  • 1
jub0bs
  • 60,866
  • 25
  • 183
  • 186
0

You can look to the documentation.

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

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

First repository and then the branch. But if you don't specify the branch name he takes the same name of the branch you actually checked out.

René Höhle
  • 26,716
  • 22
  • 73
  • 82