Todd's answer covers the command line. (--ff-only
, which can also configure as the default merging strategy for the git command-line.)
If you use GitLab, you're a maintainer of a repository and you're merging merge requests from other developers. If you want to avoid the merge requests from being created, open Settings -> Merge Requests in the repository and force the fast-forward merges only:
This will prevent the merge commits only when merging using merge requests. If you use also the command-line git merge
, you need the above solution in addition.
The disadvantage of this setting is that if you have many people working on the same sources, they will have to often rebase their feature branches, as changes from their colleagues will be getting merged before theirs. But it might be a small price to pay for having a nice commit history.
How does it look like? If merging a merge request with the fast-forward strategy isn't possible, developers will get a small Rebase button on the page with their merge request:
They can either click on the button to rebase their feature branch using the web UI, or they can do the rebase on the command-line and force-push their feature branch to the remote. This usually triggers another pipeline to build and test the change again.
If you use GitHub, it's simpler. At first, GitHub tries rebasing the feature branches automatically, as soon as the target branch of the pull request changes. If the rebasing has no conflicts, you don't need to do it manually. Secondly, if you want to avoid the merge commits from being created, perform the merge using the last menu item from the dropdown, not by clicking on button directly, which allows creating merge commits: