Reputation: 1542
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
Reputation: 70663
You are slightly misinterpreting your situation:
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.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