Lukasz Blasiak
Lukasz Blasiak

Reputation: 652

How does GitLab merge request with squash work under the hood?

On a daily basis I am working with GitLab with following workflow:

  1. I create a new feature branch from main branch
  2. I commit and push changes to the feature branch
  3. Then I create a new merge request (from feature into main) via GitLab GUI using squash feature: enter image description here
  4. When approver accept my MR, it results with following main branch tree (from IntellJ IDEA): enter image description here

I have tried to achieve the same on my testing repository using command line only but with no success so far. I have tried (on feature branch) interactive rebase as well as soft reset with force push but it always results as a 'single line tree'. Example after two separate merges from feature into main:

git checkout main
git merge <feature_branch_name>

enter image description here

Does anyone know how it works under the hood (command by command)? According to this issue it uses soft reset but it's only someone's guess. I was also searching in official documentation but with no success so far. Thanks in advance!

Upvotes: 0

Views: 418

Answers (1)

&#212;rel
&#212;rel

Reputation: 7632

Simply use merge without fast-forward:

git merge --no-ff

https://git-scm.com/docs/git-merge#Documentation/git-merge.txt---no-ff

This will create the merge as you want

You can make it the default

Put in your config file ( $HOME/.gitconfig on linux)

[merge]
    ff = no
    commit = no

You can also use git-config to do this:

  git config --global merge.commit no
  git config --global merge.ff no

Upvotes: 1

Related Questions