More than 1 year has passed since last update.

posted at

git pushしたらfetch firstでrejectedになった時の対処法


git pushしたところ下記のエラーが発生

$ git push origin master
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to ''
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.


GitHubへのpushが「fetch first」と表示されてrejectedとなったときの対処

1.git statusで状況を確認する。

$ git status
On branch master
You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)

Unmerged paths:
  (use "git add <file>..." to mark resolution)

    both added:      index.html

index.htmlがマージされていないのでgit addgit commitをしろとのこと。

2.$ git add index.html
3.$ git commit -m "2nd commit"
4.$ git push origin master

※適宜git statusで状況を確認するとよい。

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
What you can do with signing up