1

I've read answers to variations of this basic question but I'm still confused. When I enter the following git command:

git push remote_repo cool_branch

How does git treat the 'cool_branch'?

  1. Is it the LOCAL branch, from which the changes are going to be transferred to 'remote_repo' repository? If so, to which remote branch will the changes pushed?

  2. Is it the REMOTE branch to which the changes are going to be pushed? If so, from which local branch will git take the changes that it is going to push?

Which of the two options is the correct one?

Regarding 'tracking branches', from what I understood, those are local branch that "know" from which remote brunches they fetch, and "know" to which remote branches do they push. Am I right?

ykg
  • 41
  • 3

1 Answers1

0

cool_branch is a refspec (see git push refspec man page)

The format of a <refspec> parameter is an optional plus +, followed by the source object <src>, followed by a colon :, followed by the destination ref <dst>.

missing :<dst> means to update the same ref as the <src>.

A remote tracking branch is one created in the remotes namespace (refs/remotes/branch1), and which memorizes the latest SHA1 fetched from that remote for that branch.

A "local" tracking branch is a local branch (in refs/heads/aBranch) which has set an upstream branch, meaning which is associated with a remote tracking branch.
This is done with git branch -u: see "Make an existing Git branch track a remote branch?".

See more with:

Community
  • 1
  • 1
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • Let's say I do: git branch -u upstream/remote_branch local_branch. After this command, when checked out to "local_branch", Will every parameterless 'git push' will push the changes to upstream/remote_branch? Is the same true for 'git pull'? – ykg Nov 07 '14 at 12:56
  • @ykg yes. the upstream branch is recorded in the configuration of said branch and will be used for pull and push. See http://www.gitguys.com/topics/the-configuration-file-branch-section/ – VonC Nov 07 '14 at 13:09