質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Git

Gitはオープンソースの分散バージョン管理システム(DVCS)です。

Q&A

解決済

1回答

3274閲覧

git pushのエラーがなおりません

AlbertVerlnich

総合スコア2

Git

Gitはオープンソースの分散バージョン管理システム(DVCS)です。

0グッド

0クリップ

投稿2020/12/25 11:47

編集2020/12/25 12:08

前提・実現したいこと

ローカルで作業が進んだので、リモートリポジトリのchoブランチにgit pushしたいのですが、git push origin master:choでやろうとしたら以下のようなエラーが出てgit pushできませんでした。

To https://github.com/aaa

! [rejected] master -> cho (non-fast-forward)
error: failed to push some refs to 'https://github.com/aaa'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and 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.

git pullすると良いと聞いたのでgit pull origin masterは問題なく実行できました。

From https://github.com/aaa

  • branch master -> FETCH_HEAD

Already up to date.

そこで再びgit push origin master:choを実行してみたのですが、同じエラーメッセージが出てきて失敗してしまいます。
どうすればgit pushできるでしょうか?

発生している問題・エラーメッセージ

> To https://github.com/aaa ! [rejected] master -> cho (non-fast-forward) error: failed to push some refs to 'https://github.com/aaa' hint: Updates were rejected because a pushed branch tip is behind its remote hint: counterpart. Check out this branch and 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.

補足情報(FW/ツールのバージョンなど)

ちなみにローカルのgitの環境はこんな感じです。
% git remote -v

origin https://github.com/aaa (fetch)
origin https://github.com/aaa (push)

% git branch

cho
*master

% git status

On branch master
Your branch is ahead of 'origin/master' by 3 commits.
(use "git push" to publish your local commits)
nothing to commit, working tree clean

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

ローカルの別のディレクトリで新しくgit initを行い、そこに作業ファイルを持ってきてgit push origin masterを行いました。この環境でgit push origin master:choをやっても同じエラーが起こったので、choブランチにpushすることを諦めてmasterにpushしています。
(ローカル環境を変えてもエラーの文は同じだったので、エラーの原因は恐らくリモートリポジトリのchoブランチの方にあると思われます。)
お騒がせしました。

投稿2020/12/25 14:10

AlbertVerlnich

総合スコア2

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

hoshi-takanori

2020/12/26 09:25

すでに解決されたようですし、対処法としては別ブランチ (master でもいいけど、cho2 とかを作るのが普通かも) にコミットするというので構わないとは思いますが、原因はちゃんと理解しておくことをお勧めします。 hint: Updates were rejected because a pushed branch tip is behind its remote hint: counterpart. (以下略) というエラーは、remote ブランチが A -> B -> C (C は他の人や、別のマシン、または別の作業ディレクトリで push したもの) という状況の時に、ローカルで A -> B -> D みたいな状況のものを push しようとすると発生します。正しい対処法としては、ローカルで C の修正をマージ (衝突が発生すればそれを解決) してから push することですが、C の変更内容が不要であれば C を無視しても構わないと思います。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問