17
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Gitの初期設定時にmasterからmainへbranch名を変更できない場合の対処法

Last updated at Posted at 2021-05-03

超絶初心者です。

#masterからmainへ変更する際のエラー
git initコマンドを実行後、git branch -M mainを行うとエラー。

/work/project$ git init
/work/project$ git branch -M main
error: refname refs/heads/master not found
fatal: Branch rename failed

REDEME.mdファイルを作成後、addとcommitを行った後に再度実行すると成功。

/work/project$ echo "# project" >> README.md
/work/project$ git add README.md
/work/project$ git commit -m "first commit"
/work/project$ git branch -M main

成功後に確認すると、refs/heads/にmainファイルが作成されていた。
失敗した段階ではrefs/heads/にはmasterファイルがなかった。
恐らく、addまたはcommitを実行した際にmasterファイルが作成され、そのためmasterからmainへのbranch名の書き換えが成功したっぽい。

17
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?