@maneshinboys

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

githubにpushできない

解決したいこと

Ruby on RailsでWebアプリをつくっています。
githubにpushした際に以下のエラーが起こりました。
解決方法を教えて下さい。

発生している問題・エラー

! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'github.com:maneshinboys/portfolio.git'
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.

自分で試したこと

git merge --allow-unrelated-histories コマンドを打つ
⇒fatal: No remote for the current branch. の表示

初学者で、勉強不足なのでここで止まってしまいました。。
どうぞよろしくお願いいたします。

0 likes

3Answer

ローカルとリモートで共に変更があるため,このままではpushすることができません.
まずはgit pullを行って,双方の変更内容をレビューしてください.

1Like

Comments

  1. @maneshinboys

    Questioner

    ご回答ありがとうございます!
    git pullを行ったところ、

    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]

    を行ったところ、

    * branch master -> FETCH_HEAD
    hint: You have divergent branches and need to specify how to reconcile them.
    hint: You can do so by running one of the following commands sometime before
    hint: your next pull:
    hint:
    hint: git config pull.rebase false # merge
    hint: git config pull.rebase true # rebase
    hint: git config pull.ff only # fast-forward only
    hint:
    hint: You can replace "git config" with "git config --global" to set a default
    hint: preference for all repositories. You can also pass --rebase, --no-rebase,
    hint: or --ff-only on the command line to override the configured default per
    hint: invocation.

    このような表示がありました。
  2. とりあえず
    git config pull.rebase false
    を実行したあともう一度git pullしてみてください.
    ローカルとリモートの内容をマージしたコミットが作られるか,変更したファイルによってはコンフリクトが発生するはずです.
  3. @maneshinboys

    Questioner

    git pull したところターミナル内の表記が代わりました。
    そちらの画面をスクリーンショットした画像を投稿します。

このような画面です。
見えますでしょうか?

ローカルとリモートのマージコミットを作成している段階と思われます.
マージコミットのコミットメッセージを1行目に入力して(わかりやすければなんでもよい),Ctrl+Oで(名前はそのまま)保存したのちCtrl+Xでエディタから抜けてください.

その画面レイアウトはnanoというエディタのものなので,詳しくはnanoの使い方を調べてください.
エディタから抜けると,gitの作業を再開できるはずです.

1Like

Comments

  1. @maneshinboys

    Questioner

    gitの作業を開始できました!
    ありがとうございます!


    * branch master -> FETCH_HEAD
    Merge made by the 'ort' strategy.

    このような表記になっていました。
  2. @maneshinboys

    Questioner

    push してみたところ、無事pushされました!
    本当にありがとうございましたm(__)m

Comments

  1. @maneshinboys

    Questioner

    git githubを始めたばかりなので、こちらは初めて見る画面です(..;)

Your answer might help someone💌