1

Till now what I know from my previous usages is that,

git checkout -b branchName 

creates a new branch and switches the branch to branchName

the new component origin/master is the part I have got no clue about.

Note: while solving a merge conflict gitHub suggested the following

git checkout -b master origin/master

Can anyone explain what is the role of this argument & what '/' does there?

Athul Muralidharan
  • 693
  • 1
  • 10
  • 18
  • Do you know that `origin` is what Git calls a *remote*, and that `origin/*` are *remote-tracking names*? If not, start with these. The `/` itself is not particularly special, but any `origin/...` name should refer to one of these "remote-tracking" names, which exist because you `git fetch` or `git pull` from a *remote* that you call `origin`. – torek Mar 20 '18 at 15:16

2 Answers2

1

it simply separate between the remote (the repo) to the branch name

git checkout -b <branch> <remote>/<branch>

it sets the upstream of the new branch, without using this option e.g

git checkout -b <branch>

the branch is only created locally without upstream attached at the server you can find more info here https://git-scm.com/docs/git-checkout

shahaf
  • 4,750
  • 2
  • 29
  • 32
  • @abdul-wahab not to duplicate answers, I refer you to a great thread the deal with this discussion https://stackoverflow.com/questions/2739376/definition-of-downstream-and-upstream – shahaf Mar 20 '18 at 09:02
  • 1
    he didn't ask about upstream... I answered what he asked and I assume that knowing basic git he knows what upstream is (a few pushes will do it) maybe I should explain also what is git... – shahaf Mar 20 '18 at 09:19
1

Let's assume, on your remote git repository (named origin), you have a branch rbranch, then:

git checkout -b lbranch origin/rbranch

will create lbranch and track origin/rbranch. i.e.

  1. Create the lbranch branch (if not already created) and track the remote tracking branch origin/rbranch.

  2. Or reset lbranch (if already created) to the point referenced by origin/rbranch.

Since master is the default branch and already tracks origin/master, the below command:

git checkout -b master origin/master

will checkout master. And will reset the local master branch to the same head remote branch in on (if they were on different heads).


Tracking means that a local branch has its upstream set to a remote branch. More here.

Upstream means communication from local to remote. More here.

abdul-wahab
  • 2,182
  • 3
  • 21
  • 35