Reputation: 100426
I ran the following commands:
(we have a staging branch called "master_next")
(1) git fetch origin
(2) git checkout -b origin/master_next
now, when I run
(3) git branch
I see some weird stuff. Instead of seeing
master
master_next
I see
master
origin/master_next
why is the branch I just checked out preceded with "origin" - is it somehow different?
here is the exact results:
CACSVML-13295:smartconnect amills001c$ git fetch origin
From http://github.csv.comcast.com/Baymax/smartconnect
* [new branch] master_next -> origin/master_next
* [new tag] 0.0.2 -> 0.0.2
* [new tag] 0.0.3 -> 0.0.3
CACSVML-13295:smartconnect amills001c$ git checkout -b origin/master_next
Switched to a new branch 'origin/master_next'
CACSVML-13295:smartconnect amills001c$ git branch
master
* origin/master_next //wth?
can anyone explain why this happened and how origin/master_next might be different than plain-old master_next?
Upvotes: 1
Views: 76
Reputation: 9703
You likely meant to use the -t
option.
git checkout -t origin/branchname
will create a new local branch at the commit, that branchname
on the origin
remote is pointing to. It will at the same time set up that new local branch to track the remote branch. This means that you will be able to pull from and push to it with your local branch.
git checkout -b branchname
will create a new local branch at the commit that you are currently at.
Upvotes: 2
Reputation: 1224
git checkout -b origin/master_next
creates a new branch. -b is used to make a new branch. Instead try git checkout master_next
Upvotes: 1
Reputation: 47906
The problem was in this command:
git checkout -b origin/master_next
This command created a new branch origin/master_next
instead of checking out the branch master_next
that was created remotely.
What you should have done:
git fetch origin
git checkout master_next
git branch
The git checkout branch_name
command with -b
creates a new branch branch_name
and then checkouts to that branch.
git checkout -b new_branch_name #will create new branch and checkout to it
Upvotes: 1