Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is fast-forwarding push in the Git?

Tags:

git

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?

like image 425
Andrey Bushman Avatar asked Sep 10 '15 12:09

Andrey Bushman


People also ask

What exactly does git push do?

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.

What does non-Fast-forward mean in git?

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.

How resolve git push rejected non-fast-forward?

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.


1 Answers

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
like image 72
Jonathan.Brink Avatar answered Oct 20 '22 19:10

Jonathan.Brink