From the Git documentation:
By default, the configuration flag receive.denyNonFastForwards is enabled in shared repositories, so that you cannot force a non fast-forwarding push into it.
I know about the git push
command, but what is fast-forwarding push?
The git push command is used to upload local repository content to a remote repository. Pushing is how you transfer commits from your local repository to a remote repo. It's the counterpart to git fetch , but whereas fetching imports commits to local branches, pushing exports commits to remote branches.
A non-fast-forward merge is a merge where the main branch had intervening changes between the branch point and the merge back to the main branch. In this case, a user can simulate a fast-forward by rebasing rather than merging.
If you do a commit in one project and then accidentally push this commit, with bypassing code review, to another project, this will fail with the error message 'non-fast forward'. To fix the problem you should check the push specification and verify that you are pushing the commit to the correct project.
Basically this means that you won't be re-writing commit history that already exists on your Git server (the already-pushed stuff).
If this history changes it could be a problem for others who have already pulled and worked off that history.
A manual way to determine if you are pushing "fast forward" is to look at what ref you have for your downloaded copy of your branches remote (let's say master):
git rev-parse origin/master #returns sha
Then, download the content from your remote server and check again:
git fetch
git rev-parse origin/master #returns sha
If the return result of those those two rev-parse commands are equal your push will be fast-forward.
BUT...all that work really isn't necessary. Just simply pull before you push and you will be good.
git pull origin master
# resolve any conflicts
git push origin master
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With