We're ending up with a lot of commits like this in our repo:
Merge branch 'master' of bitbucket.org:user/repo
This happens every time a developer syncs his/hers local fork to the top-level repo.
Is there anyway to avoid this merge-commit hell from cluttering all the repo log? Can one avoid them when initiating the pull-requests in some way?
I know I can do git rebase if this is done in my local VM only, is there any equivalence in the GitHub/BitBucket UI?
How do you guys do it?
When you select the Rebase and merge option on a pull request on GitHub.com, all commits from the topic branch (or head branch) are added onto the base branch individually without a merge commit. In that way, the rebase and merge behavior resembles a fast-forward merge by maintaining a linear project history.
You can use the git reset --merge command. You can also use the git merge --abort command.
With --no-commit perform the merge and stop just before creating a merge commit, to give the user a chance to inspect and further tweak the merge result before committing. Note that fast-forward updates do not create a merge commit and therefore there is no way to stop those merges with --no-commit.
If you want to avoid merge commits, you need to ensure all commits are fast-forwards. You do this by making sure your feature branch rebases cleanly onto your line of development before a merge like so:
git checkout master git checkout -b feature/foo # make some commits git rebase master git checkout master git merge --ff-only feature/foo
Rebase also has a lot of flags, including interactive rebasing with the -i
flag, but you may not need that if you're keeping things as simple as possible and want to preserve all of your branch history on a merge.
--ff-only
FlagAside from rebasing, the use of the --ff-only
flag will ensure that only fast-forward commits are allowed. A commit will not be made if it would be a merge commit instead. The git-merge(1) manual page says:
--ff-only
Refuse to merge and exit with a non-zero status unless the current HEAD is already up-to-date or the merge can be resolved as a fast-forward.
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