How do I resolve this issue? I am trying to commit but I get the below error.
git push origin monty_svm_dev
To git@github.com: ! [rejected] monty_svm_dev -> monty_svm_dev
(non-fast-forward) error: failed to push some refs to
'git@github.com:/mygit.git' To prevent you from losing history,
non-fast-forward updates were rejected Merge the remote changes before
pushing again. See the 'Note about fast-forwards' section of 'git
push --help' for details. root@li409-202:~/mypath#
do git pull origin monty_svm_dev
first
What has happened is that the remote has more recent changes than your branch.
So before you can push
your changes, you need to get and merge the changes on the remote first.
You can do this either by doing a git checkout your_branch
, then:
git fetch origin your_branch
and then a
git merge your_branch
or
git pull origin your_branch # fetch and merge in one operation
Where your branch is master, or your branch name (seems to be monty_svm_dev
in your case I think)
Once this is done (and any conflicts resolved) you can do a git push origin monty_svm_dev
It basically because when you
git pull
from a branch , two operations take place fetch and merge. Now if your local has some changes then git will not allow you to push it before you commit your changes.
Also this issue appears if the remote has changes which are still not pulled in local and merged, so you need to take a pull again and then push it. Do reply if it doen't solve the issue
Do a Git pull. Then it will bring recent code changes in remote branch into your local. then you are able to push your changes.
This issue arises when the user forgets to issue git push
command after git commit
command. When using git, please always make sure the basic steps.
In an ideal cycle while working with git, always check the following git commands were used sequentially in the following order:
git pull
git add
git commit
git push
I personally avoid majority of the issues posted about git on stack, because I always tally my git command acitivites to the above sequence.
I created an acronym to make sure I don't forget, I am hopoing the same can be useful to the reader which is:
pacp (read it as: pack push where (p=git push, a=git add, ck=git commit, push=git push).
My way to memorise the git push, add, commit, pull is:
get pack push (meaning: git the pack and then push).
In summary remember to "git" the pack and then "push".
Resolving the issues: I would like to add my most used recovery git commands that are:
git checkout -- path/to/file/fileName.something #undo changes in file
The above undoes the changes in a file...similar can be applied for multiple files using * for file name, similarly can be applied to multiple directories separated by space.
git reset filename.txt
The above removes the file from stage...after this command we can safely do git commit and git will only commit those files we are in stage which means the file "filname.txt" won't get committed)
git pull origin your_intended_branch
Changes are merged with the latest from your_intended_branch this basically merges the change which you committed but did not push. Once all goes fine, simply do the push:
git push
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.