Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to checkout merge request locally, and create new local branch?

I have GitLab repository there and I need to test every merge request locally, before merging to the target branch.

How can I pull/fetch merge request as a new branch?

like image 608
Lokinder Singh Chauhan Avatar asked Jul 09 '17 02:07

Lokinder Singh Chauhan


People also ask

How do I merge local main to local branch?

To merge branches locally, use git checkout to switch to the branch you want to merge into. This branch is typically the main branch. Next, use git merge and specify the name of the other branch to bring into this branch. This example merges the jeff/feature1 branch into the main branch.

How do I checkout a pullout locally?

To check out a pull request locally, use the gh pr checkout subcommand. Replace pull-request with the number, URL, or head branch of the pull request.


2 Answers

  1. Pull merge request to new branch

    git fetch origin merge-requests/REQUESTID/head:BRANCHNAME

    i.e git fetch origin merge-requests/10/head:file_upload

  2. Checkout to newly created branch

    git checkout BRANCHNAME

    i.e (git checkout file_upload)

OR with single command

git fetch origin merge-requests/REQUESTID/head:BRANCHNAME && git checkout BRANCHNAME

i.e git fetch origin merge-requests/18/head:file_upload && git checkout file_upload

like image 103
Lokinder Singh Chauhan Avatar answered Sep 23 '22 18:09

Lokinder Singh Chauhan


This is also documented in GitLab online documentation : https://docs.gitlab.com/ee/user/project/merge_requests/reviewing_and_managing_merge_requests.html#checkout-merge-requests-locally-through-the-head-ref

They supply this script (git alias) :

[alias]     mr = !sh -c 'git fetch $1 merge-requests/$2/head:mr-$1-$2 && git checkout mr-$1-$2' - 

Then you can use this command :

git mr origin 4

So a new local branch mr-origin-4 will be created.

like image 39
Guillaume Husta Avatar answered Sep 23 '22 18:09

Guillaume Husta