LoginSignup
0
0

More than 3 years have passed since last update.

git push でリジェクトされた時の対処法

Posted at

はじめに

githubを利用してプログラミング開発を実施されている方、およびgithubを使ってからあまり日がたっていない方が対象になるかと思います。

Githubのバージョン

$ git --version
git version 2.17.2

エラーの内容

git pushコマンドを使ってmasterブランチに修正したソースをpushしようとした際に以下のようなエラーが出ました。

//git pushコマンド
$ git push origin master

//エラー内容
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/・・・・'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.`

対象方法

色々と調べてみるとたくさん出てきましたが、一番心あたりがあるのが、
「リモートリポジトリ側の変更がローカルに反映されていない」ということが書かれていた
以下のサイトでした。

対象のリンク

以下のコマンドを実施したら上手く行きました。

$ git fetch
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 2), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/・・・
   c35643a..4d9b4f1  master     -> origin/master

$ git merge origin/master
Updating c35643a..4d9b4f1
Fast-forward
 index.html | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

$ git push -u origin master
Branch 'master' set up to track remote branch 'master' from 'origin'.
Everything up-to-date

catコマンドで修正した内容がちゃんと反映されているか確認しましたが、問題なくファイルが更新されておりました。

0
0
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
0
0