LoginSignup
11
4

More than 3 years have passed since last update.

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

Posted at

エラー発生

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

$ git push origin master
To https://github.com/xxx/xxx.github.io.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/xxx/xxx.github.io.git'
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で状況を確認するとよい。

11
4
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
11
4