206
155

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

git pushがreject(拒否)されたときの対処法

Posted at

リモートにプッシュした時、次のようなエラーが返ってきた。

To github.com:○○○○○○/○○○○○○○
 ! [rejected]        master -> master (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.

##状況確認
non-fast-forward は、下のような状況で言うとmasterブランチのリモートとローカルの最新情報が異なっていることを示す。そのため、通常のプッシュが行えず、rejectが表示される。

master    a --- b --- c --- d --- e
(リモート)
          
master    a --- b --- c --- d --- f
(ローカル)     

##対処法1

$ git pull origin master  リモートの情報をローカルに持ってくる(自動的にマージも行われる)
$ git push origin master  最新情報が一致するため通常のプッシュが行える

##対処法2

$ git push -f origin master   強制(force)的にプッシュする
206
155
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
206
155

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?