状況
方法
以下コマンドのように、あらたに登録する。
git remote add origin git@github.com:kotakanazawa/blog.git
pushしようとしてもリジェクトされるので、-f
オプションでpushする。
git push -f origin main
かなりの破壊的変更になるので注意が必要。
また、これだとmainブランチでgit pull
をするとトラッキング情報がないと言われると思う。
$ git pull There is no tracking information for the current branch. Please specify which branch you want to merge with. See git-pull(1) for details. git pull <remote> <branch> If you wish to set tracking information for this branch you can do so with: git branch --set-upstream-to=origin/<branch> main
この場合、git pull origin main
をすればいつもどおりリポジトリの情報を落とせる。しかし毎回これをするのはちょっと面倒。
そんな場合、エラーメッセージにもあるように、リモートのmainブランチをトラッキングすればよい。
$ git branch --set-upstream-to=origin/main main
Git で git pull するとマージすべきブランチがわからないと言われる場合の対処方法 | gotohayato.com