Athul Muralidharan
Athul Muralidharan

Reputation: 753

what does this command git checkout -b master origin/master do?

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?

Upvotes: 1

Views: 3265

Answers (2)

abdul-wahab
abdul-wahab

Reputation: 2272

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.

Upvotes: 1

shahaf
shahaf

Reputation: 4983

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

Upvotes: 1

Related Questions