1

I understand that the -u argument in git push associates a local branch with its corresponding remote branch so that git pull and git push can be used without additional arguments.

However, as this answer (https://stackoverflow.com/a/16018004/8278160) states:

 git push -u origin master

Is the same as:

 git push origin master; git branch --set-upstream master origin/master

As Casey Li states in this video (https://www.youtube.com/watch?v=XogN0Q4sb9o), the format origin/repo is used to designate a remote tracking branch.

As such, does git branch --set-upstream master origin/master in the line above associate the local branch, master, with its corresponding remote tracking branch (origin/master), or to the remote branch directly?

Gokhan
  • 307
  • 3
  • 9
  • *“… with its corresponding remote tracking branch (origin/master), or to the remote branch directly?”* Those sound like the same thing? – Ry- Aug 03 '17 at 04:20
  • @Ryan This answer states otherwise (https://stackoverflow.com/a/16408515/8278160), and is the main reason I'm confused. – Gokhan Aug 03 '17 at 04:24
  • It ssociates the local branch with both the remote tracking branch and the remote branch. For `git push`, the remote tracking branch and the remote branch are updated according to the local branch. For `git pull`, the remote tracking branch and the local branch are updated according to the remote branch. Note that the remote branch and the remote tracking branch for `git push` can be different from those for `git pull`. You can pull from repoA and push to repoB. – ElpieKay Aug 03 '17 at 04:34
  • Note that `git push ` effectively expands to `git push :`. This asks the Git at `` to set its own `` (expanded, if necessary, so that `git push newbr` winds up being like `git push :refs/heads/`). If that succeeds, it implies that `` on the remote now maps to the corresponding hash ID, so now your own Git updates **or creates** the remote-tracking-branch, typically named `refs/remotes//`. Once `refs/remotes//` exists in your own repo, your Git can set it as the upstream. – torek Aug 03 '17 at 05:44

1 Answers1

2

associate the local branch, master, with its corresponding remote tracking branch (origin/master), or to the remote branch directly?

In a local repo, there is no remote branches, only remote tracking branches, which are local branches tracing (ie keeping a copy of the last known state of) remote branches fetched in the repo.

See more at "Having a hard time understanding git-fetch".

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250