FortyTwo FortyTwo - 5 days ago 5x
Git Question

Sync commit history of master and develop

I am using master as a production branch which is fetched nightly onto many servers as read only. Master should never be ahead of develop because I only push to develop. When develop is stable, I want to fast forward master to match it.

I am currently doing this with:
git checkout master
git pull origin develop
git push origin +master

This works for me and syncs everything nicely, but it feels a bit wrong. There is another dev on my team that likes to just merge develop into master like a normal person. However, merging creates a merge git which makes master 1 commit ahead of develop. These build up over time and makes the git history unclean and annoying to look at. If I do my branch cloning hack, those merge commits disappear on remote but remain on my team's local branch.

I tried git rebase and git merge --ff, but those change hashes which still show as uneven.

Summary: How do I cleanly fast forward master to be perfectly even with develop? Or am I just not using git the way it is meant to be?


Generally your flow seems to be right. But since it is an absolute requirement to do a fast-forward only, you should pass --ff-only to enforce it.

git checkout master 
git fetch origin
git merge --ff-only origin/develop
git push origin master

--ff is not needed, since fast-forward is a default behavior.

I tried git rebase and git merge --ff, but those change hashes which still show as uneven.

Fast-forward merge by definition never creates merge commit, but only updates the branch pointer:

--ff When the merge resolves as a fast-forward, only update the branch pointer, without creating a merge commit. This is the default behavior.