Why has Git allowed me to create two branches with the same name?

前端 未结 5 1224
不思量自难忘°
不思量自难忘° 2020-12-29 18:09

I\'m still relatively new to Git and I have made a bit of a mess of my repository. I\'m hoping there is a way to fix it without re-cloning.

I have a repository whic

5条回答
  •  醉话见心
    2020-12-29 18:49

    I made a similar mistake (creating a local branch named origin/...) a couple of times.

    To protect against this sort of mistakes (and assuming you will never want a local branch whose name actually starts with origin/) you can run the following commands in repo/.git/refs/heads:

    mklink /d remotes nul
    mklink /d origin nul
    mklink /d upstream nul
    

    They create symlinks to nul that would prevent creating subdirectories under those names. Now accidental mistakes like git branch origin/feature will give an error:

    unable to create directory for .git/refs/heads/origin/feature
    

提交回复
热议问题