Search code examples
gitgitlabgit-mergegit-rebase

Git Merge a branch to master on GitLab


I've got a basic question here.

I have a branch called: foo I have created a merge request for "foo".

GitLab says there are merge conflicts with master so I can't auto merge. This is because there's a file called foo.txt that has the same line changed in the master and branch (foo).

What are my options available here? One option is:

git fetch origin
git checkout origin/master
git merge --no-ff foo
git push origin master

But I wouldn't want the developers to have a direct push access to the master.

How can I make my branch in a merge ready condition so that I can use GitLab's "Auto Merge" option?

Can I know the recommended workflow here?


Solution

  • You can resolve the conflicts on branch foo:

    git checkout foo
    git merge master
    # resolve conflicts 
    git merge --continue
    

    Now you have the state intended for master on branch foo. You can merge onto master without any conflicts:

    git checkout master
    git merge --no-ff foo