やってみる

アウトプットすべく己を導くためのブログ。その試行錯誤すらたれ流す。

git push すると rejected と怒られた

謎のエラー。調べてみた。

問題

git pushすると以下のようにrejectedと怒られた。なにこれ?

 ! [rejected]        master -> master (fetch first)
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.

pull

git pullしろとあるので、やってみた。

$ git pull
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 4 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (4/4), done.
From https://github.com/ytyaru/JS.requier.20180417161744
   add8b7c..0ad8b21  master     -> origin/master
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> master

エラー。リモートとブランチを指定しろと。

$ git pull origin master

なんかvim開いた。

Merge branch 'master' of https://github.com/ytyaru/JS.requier.20180417161744

# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.

末尾に以下を追記して:wqした。

git push すると rejected と怒られたのでpullした。

画面がターミナルに戻り、以下のようになっていた。

$ git pull origin master
From https://github.com/ytyaru/JS.requier.20180417161744
 * branch            master     -> FETCH_HEAD
Merge made by the 'recursive' strategy.
 docs/_config.yml | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 docs/_config.yml

原因

サーバ側にファイルできていたのに、ローカル側にそれがないままpushしたせい。

出力結果を見てみるとdocs/_config.ymlというファイルがある。docs/_config.ymlGitHubでWebページを作成する時に自動作成されるやつ。たぶんこいつがローカルに存在していないから「整合性とれていないぞ」と怒られたんだろう。

そういえば、pushする前にWebページ作成する設定をGitHubサイトのSettingページで行った。そのときにdocs/_config.ymlがリモート側にできたのだろう。ローカルでは一度もpullしてなかった。サーバ側でできたdocs/_config.ymlをダウンロード(pull)してからpushすべきだった。

push

その後、$ git pushができた。