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?
You are slightly misinterpreting your situation:
feature/form, the remote has branch a namedfeature. Now this may come as a surprise, but these names conflict.feature/formactually 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/featuretries to create a branch named “feature”, which is not possible, so it fails.featurebranch without deleting or renaming your localfeature/formbranch – even though I would not really recommend that as it’s easy to get confused there.Running this command:
will generate a local branch named
mylocalnamethat tracks the remote branchfeatureon the remoteorigin.