Amadeu Cabanilles
Amadeu Cabanilles

Reputation: 963

GIT: create and get Branch from a previous commit

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.

Upvotes: 0

Views: 55

Answers (3)

Krishnamoorthy Acharya
Krishnamoorthy Acharya

Reputation: 4244

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

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

Upvotes: 0

Sébastien Dawans
Sébastien Dawans

Reputation: 4616

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).

Upvotes: 1

xate
xate

Reputation: 6379

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

Upvotes: 4

Related Questions