Lazygit's M Key Hides Four Merge Options — Here's the Git History Each One Leaves Behind
I use lazygit daily, and for a long time M was just "the merge key". Press it, pick the option, the merge happens. It took me a while to actually slow down and pay attention to the options in the menu. Each option runs the same merge, but the commit graph left behind is different, and that influences the git history. So I did what I do with any keystroke I don't fully understand: I built a…
Lazygit's "M" key provides four merge options that affect the resulting commit graph and commit history. By pressing "M" on the branch you wish to merge, a panel appears with the following choices: regular merge (fast forward), regular merge (with merge commit), squash merge and leave uncommitted, and squash merge and commit. Each option creates a distinct merge graph and alters the history left behind.
To experiment, set up a throwaway repository with three commits on a feature branch. Then, open the repo in lazygit, navigate to the branches panel, and press "M". After each experiment, run "git log --oneline --graph" to observe the resulting history graph. Finally, use "git reset --hard HEAD@{1}" to switch between options.
The regular merge (fast forward) option, triggered by "m", merges the source branch into the target branch smoothly when possible. It creates a linear history without a merge commit, but lacks a clear marker for the merge. Conversely, the regular merge (with merge commit) option, triggered by "n", always generates a merge commit, marking the point where a branch landed in the target branch.
The squash merge and leave uncommitted option, activated by "s", combines the source branch's commits into a single commit on the target branch, preserving the individual commits' messages. Meanwhile, the squash merge and commit option, activated by "S", performs the same squash operation but requires you to enter a new commit message for the resulting single commit. Each option provides distinct benefits and trade-offs when merging branches in a Git repository.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.