0

I've just created a branch from a previous commit with the command

git branch thenewbranch 03771674c482e4611cc48ee120a16a91dfb2793d

Now I want to checkout the branch to work with in Eclipse with

$ git checkout -b thenewbranch

But i got this error

fatal: A branch named 'thenewbranch' already exists.

3 Answers 3

4
git checkout -b thenewbranch

means create a new branch called "thenewbranch" and then go into it

you only need to

git checkout thenewbranch

git checkout -b|-B [] Specifying -b causes a new branch to be created as if git-branch[1] were called and then checked out. In this case you can use the --track or --no-track options, which will be passed to git branch. As a convenience, --track without -b implies branch creation; see the description of --track below.

If -B is given, is created if it doesn’t exist; otherwise, it is reset. This is the transactional equivalent of

from https://git-scm.com/docs/git-checkout

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

Comments

1

You don't need to specify -b. Simply:

git branch thenewbranch 03771674c4
git checkout thenewbranch

The -b option is a different behavior, it means you actually want to create a new branch called thenewbranch from you current HEAD (implicit).

Comments

0

Always create branch and push the changes.You will not face the problem

git checkout -b newbranch 03771674c482e4611cc48ee120a16a91dfb2793d
git push --set-upstream origin newbranch

4 Comments

Unearth a 8 years old question to add an off-topic precision? Seems unnecessary. Or maybe it's me who failed to see the link with OP's question? We don't know if their repo even has a remote, to begin with. And either way it's relevant to the initial confusion OP faced.
Today I had faced same issue..i created branch with checkout did not push it..then i found that commit id is wrong and tried again with new branch git push
@RomainValeri thanks for reminding me 2016 is 8 years ago.. seems to be 4 years back
I must admit you have a point there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.