To make a fast-forward merge, first we need to switch to the branch that we want to merge into. Then we use the git merge command. For example, if we want to merge a branch called bugfix into master we run
git merge bugfix
Fast-forward merges have one disadvantage compared to three-way merges. Since they don't have a merge commit, undoing the merge (for example if there was a bug in the merged code) can be hard. So we usually tell Git to not do an ff-merge, even if it's possible. Let's see this in an example.
Since we don't need the old bugfix branch anymore (because all its content has already been merged into master), we delete it and create a new bugfix branch where we'll fix a new bug. Once the bug is fixed, we stage and commit the changes, and switch to master. To merge we run
git merge --no-ff bugfix
VS Code will open and we'll be asked to write a commit message. In general, the default message is OK. When we close the VS Code tab, Git will carry out the merge, using a three-way merge strategy.
Now let's check our log, but using the --graph option. So we run
git log --oneline --all --graph -5
This will show a one-line log of our last 5 commits from all branches, using the graph display. Here we can see that commit 4188bbb was created as a commit message that combined commits e6614d7 and d106b04.
We can disable fast-forward merges by running
git config ff no
This will disable them for this repository alone. If you want to disable them for all repositories, just add the --global option.