こんにちは。
なんかすでに秋風の涼しさを感じた日がありました。
どうもハチマキです。
はじめに
git push時に発生したrejected(エラー)を初めて解決した時に結構苦戦したので、
同じ境地に立たされている方のソリューションになればと思います。
結論!めちゃ簡単でした。
本日の概要 : git pushがrejectedされた時の解決方法
事象
git push origin testでtest branchをpushした際にrejectedが発生
エラー例
$ git push origin test To github.com:~~~~ ! [rejected] test -> test (non-fast-forward) error: failed to push some refs to 'git@github.com:~~~~ hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g. hint: 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
問題点
端的に言うと、testブランチのリモートとローカルの最新情報が異なっているため、pushが行えずrejectされる。
こんなときに発生する
- 別の人が同じブランチにすでにプッシュしてしまった
- すでにコミット状態の中、ローカルのコードを新たに変更してpushした
など
解決方法
リポジトリを最新状態にすることで解決します。
$ git pull origin test 対象ブランチを最新にするため、pullする $ git push origin test 再度pushする
参考資料
- git pushがreject(拒否)されたときの対処法 - Qiita
- non-fast-forward エラーの扱い - GitHub Docs
- Non-Fast-Forward Push の解決 - Linux 入門
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
日々勉強です。
以上、ハチマキでした。