32

I run:

 git checkout mygithub/master

but for some reason, running 'git status' shows "not currently on any branch". Running:

 git checkout master

and then git status, says that I'm now on branch master. Now I want to switch to another branch. Running git checkout anotherbranch works, but git status says I am still on branch 'master'. What am I doing wrong?

2
  • Does git checkout anotherbranch produce any output? Commented Aug 2, 2012 at 18:44
  • It shows no output, no error. Commented Aug 2, 2012 at 18:46

3 Answers 3

42

mygithub/master is a remote branch. To create a local branch based off of that remote branch, you have to use git checkout -b mymaster mygithub/master. Git tries to make this easy for you: if you write git checkout branchname, and branchname only exists in a remote, but not locally, Git will automatically set up a local branch with <remote>/branchname being its parent.

Sign up to request clarification or add additional context in comments.

6 Comments

So why does git checkout branchname never switch to this? Branch exists on github, I just want to merge master changes to it.
@NoBugs: git checkout -b remotemaster mygithub/master should create a new branch off mygithub/master and switch to it.
git checkout -b otherbranch mygithub/otherbranch works, but git merge mygithub/master wants to 'fast forward' and delete files from the non-master, that I want to keep.
@NoBugs: Do you want to merge mygithub/master into master, or do you want to merge master into mygithub/master? A 'fast forward' is just a special case of a merge.
@NoBugs: The branch must have an upstream branch configured or a remote branch with the same name. If this isn't the case, you can always be explicit about which branch to push: git push origin localbranch:remotebranch (I assume in your case that's git push mygithub otherbranch:otherbranch)
|
15

If you want to switch to another branch then run this command:

git checkout branch name

If you want to delete a branch then run this command:

git branch -D branch name

If you want to create a new branch then run this command:

git checkout -b branch

Comments

-7

If you want to checkout from master branch just run this command in your terminal

git checkout -b BRANCH_NAME

1 Comment

This will create a new branch. Reading the question, I do not think the poster wants to create a new branch.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.