ローカルとリモートのブランチの状況を合わせたい

はじめに

現状、ローカルとリモートのブランチの状況が異なっている。

ローカルのブランチの状況

git branchで確認すると、mainのみだった。

リモートのブランチの状況

mainとmasterの二つある。

リモートとローカルのブランチ状況を合わせて確認

hiroki@shibatahiroshitakanoMacBook-Air ki-hi-ro.com % git branch -a
* main
  remotes/origin/main
  remotes/origin/master

実現したいこと

mainブランチに統一したい。

以下のようになればOK。

hiroki@shibatahiroshitakanoMacBook-Air ki-hi-ro.com % git branch -a
* main
  remotes/origin/main

解決方法 : リモートのmasterを削除

git push origin –delete masterでリモートのmasterブランチを削除できるみたいだが、エラーが出た。

hiroki@shibatahiroshitakanoMacBook-Air ki-hi-ro.com % git push origin --delete master
To https://github.com/ki-hi-ro/ki-hi-ro.com-2022.git
 ! [remote rejected] master (refusing to delete the current branch: refs/heads/master)
error: failed to push some refs to 'https://github.com/ki-hi-ro/ki-hi-ro.com-2022.git'

現在のブランチがmasterブランチというのが原因のようだ。

リモートのGitHubで現在のブランチを変更するにはどうすればいいのか?

settingタブ > General > Default branch、ここがmasterになっているので、mainにする。

右側のボタンをクリック。

ここでmainが選択できる。

mainに変更できた。

もう一度、以下のコマンドを入力する。

hiroki@shibatahiroshitakanoMacBook-Air ki-hi-ro.com % git push origin --delete master

delete成功。

以下の状態になったので、やりたいことが実現できた。

hiroki@shibatahiroshitakanoMacBook-Air ki-hi-ro.com % git branch -a                  
* main
  remotes/origin/main

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です