エラーの背景
Gitでpushする時に以下のようなエラーが発生しました。個人によって状況が違うので参考程度でもいいかなと思います。
laravelapp % git push origin feature/noriaki/common_file
#省略
! [remote rejected] feature/noriaki/common_file -> feature/noriaki/common_file (cannot lock ref 'refs/heads/feature/noriaki/common_file': 'refs/heads/feature/noriaki' exists; cannot create 'refs/heads/feature/noriaki/common_file')
error: failed to push some refs to 'https://github.com/省略'
他にもgit fetch,git mergeを使いましたが、解決できず、
laravelapp % git pull origin develop_a_yayoi_rab
などでgit pullで試してからgit pushで試しましたが、挙動が変わりませんでした。
調べて見たエラーの意味はリモートのファイルがローカルのファイルも最新版だから、
そのファイルにpushできないですよという意味だったみたいです。
解決した方法
まずアドバイスをもらったのがfeature/noriaki というブランチを
リモートに作ってしまっているので下のコマンドでリモートブランチを削除しようということになりました。
laravelapp % git push origin --delete feature/noriaki
その後に
Username for 'https://github.com': 省略
Password for 'https://省略':
remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/省略/'
注目したのが以下の文です
fatal: Authentication failed for 'https://github.com/省略'
Githubでアクセストークンの発行が必要でした。
トークンの期限切れだったのでトークンを再発行してから再度トークンを入れてみました。
トークン再発行方法
以下の記事を参考にしてみてください。
解決
トークン発行後に以下のコマンドを実行後
laravelapp % git push origin --delete feature/noriaki
laravelapp % git push origin feature/noriaki/common_file
を実行後pushができました。
資料