*What do you want to solve?
Error: failed to push some refs to appear during git push, so I would like to resolve that.
* Assumptions
Creating web applications in Rails.
Work branch: implement_bookmark_for_post
US>Flow to Error
*Error Contents
![rejected]implement_bookmark_for_post->implement_bookmark_for_post(non-fast-forward)
error: failed to push some refs to 'https://github.com/keisuke713/cities.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.
*Tried
I tried the following command, but the error did not go away.
git pull
git fetch->git merge origin/master
git fetch->git rebase origin/master
If you know the above, please take good care of me.
git
The error itself is caused by the fact that the commitment is separated between remote and local, making it impossible to simply merge.
o---o---o (remotely pushed the wrong commit)
\---o (local has another commit growing before one miscommit)
You need to clear this gap and push it.
git pull
has a merge conflict, and if you look at git status
, you may say Your branch and 'origin/Somehow, 'have diverged,...
.
Manually remove the merge conflict according to the git status
display and push it by entering a merge commit.The final commit graph shows the confluence of the bifurcated commits as shown below.You can check the git log --graph
after all the tasks are completed.
o-----(Mistaken commit)---\
\--(correct commit)--(merge commit)
For example, you would enter the following command:
$git pull
$ git status
$ (Open the conflicted file in the editor and manually clear the conflict)
$ git add
$ git commit
$ git push
This is a way to resolve conflicts by doing git rebase
instead of git merge
.Create a new commit that summarizes the changes made on the local side.The final commit graph is as follows: disappears and is absorbed by
(rebase commit)
.
o-----(Mistaken commit)---(rebase commit)
First of all, if you do git pull
, the merge has started, so I will stop this.If you do not know if the merge has started, check with git status
.
$git merge --abort
You can then do this with git rebase origin/
.
$git rebase origin/
$ (Remove conflicts in the editor while looking at the git status.
e.g. remove conflicts in the editor and then git rebase -- continue)
$ git push
By the way, if you have not already done git pull
, you can do this at once with the command git pull --rebase
.
$git push
(Conflict Error Occurred)
$ git pull --rebase
$ (fix conflicts)
$ git push
It's a rather dangerous method compared to the other two.Please use it after you know what you are doing.
If no one has pulled that branch yet, you can force push to change the remote commit log.Typically, you can use this method in a personal repository that you only use.Use this method carefully because it rewrites the remote commit log.
The final commit graph is as follows:
o-----(correct commit)
First of all, if you do git pull
, the merge has started, so I will stop this.If you do not know if the merge has started, check with git status
.
$git merge --abort
git reset
and a new commit git commit
, so push it with the -f
option to force push.
git push-f
© 2024 OneMinuteCode. All rights reserved.