imrane
imrane

Reputation: 1542

Accidently Pulled Down Branch with the Same Name

I accidentally pulled down a branch with the same name as a local branch

* 909a2b5 - (HEAD, feature/form) xxxx <imrane>
* c9d6bc5 - xxxx <imrane>
| * 6e96409 - (origin/feature) xxx <anandmv>
|/  
*   38e35d8 - (origin/develop, origin/HEAD, develop) xxx <imrane>

I had committed all changes to my local branch, then ran

git fetch origin

and then tried to track the remote branch and got the following error

git checkout --track origin/feature
error: there are still refs under 'refs/heads/feature'
fatal: Failed to lock ref for update: Is a directory

Questions:
1. How do I revert without losing the commits I had on feature/form
2. How do I pull down the branch without having a naming collision?

Upvotes: 1

Views: 1659

Answers (1)

Chronial
Chronial

Reputation: 70663

You are slightly misinterpreting your situation:

  • You do not need to revert anything, you didn’t lose anyting
  • Your situation is as follows: You have a local branch named feature/form, the remote has branch a named feature. Now this may come as a surprise, but these names conflict. feature/form actually creates a folder named “feature” with a branch named “form" in it. Because of that you can not create a branch named “feature”, as a folder with that name already exists.
  • git checkout --track origin/feature tries to create a branch named “feature”, which is not possible, so it fails.
  • regarding question 2: Well, there just is a naming collision – these two branches can’t coexist in your local repo. But you can work on the remote feature branch without deleting or renaming your local feature/form branch – even though I would not really recommend that as it’s easy to get confused there.
  • Running this command:

    git checkout -b mylocalname --track origin/feature
    

    will generate a local branch named mylocalname that tracks the remote branch feature on the remote origin.

Upvotes: 7

Related Questions