Creation of branch with / in the name fails

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問

プラットフォームについて: Cloud、Server、および Data Center - この記事はすべてのプラットフォームに等しく適用されます。

Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Fisheye および Crucible は除く

要約

Creation of branch fails with the following error

fatal: cannot lock ref 'refs/heads/dev/feature1': 'refs/heads/dev' exists; cannot create 'refs/heads/dev/feature1'

原因

This happens because of the way git stores pointers to the HEAD of each branch in the .git/refs/heads folder. In every git repository, there exists a .git/refs/heads folder. It contains a text file for each branch on the repository that stores the commit hash for the tip of the branch. For example, if you have three branches in your repository named master, dev and feature, the files in .git/refs/heads will look like this -

$ > ls .git/refs/heads

dev feature master


Each of these files corresponds to a branch.


Creation of a new branch called "feature/first-feature" would mean creation of a file called "feature/first-feature". However, this would not be allowed since a file called feature already exists and you cannot create a file and a directory with the same name.

ソリューション

To resolve this issue, there are two workarounds -

  • Delete the branch called feature if you want to create other branches like feature/feature-1 or feature/first-feature. Please make sure that this does not impact your code since this is a destructive action.

          

git push -d origin feature
git branch -d feature


The first command deletes the remote branch. Replace origin with your remote name if it is not origin.

The second command deletes the branch remotely. This command is not required if the branch has not been pushed yet.

  • Rename your local and remote branch from feature to feature/feature-1. Name the subsequent features as feature/feature-2 and so on. A branch called just feature cannot exist.
git branch -m feature feature/feature-1
git push -d origin feature
git branch --unset-upstream feature/feature-1
git push origin feature/feature-1
git push origin -u feature/feature-1




最終更新日: 2022 年 12 月 26 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.