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

谁说胖子不能爱 提交于 2019-12-20 10:28:05

问题


I have gitlab repository there I need to test every merge request locally, before merging to target branch. How can I pull/fetch merge request as a new branch?


回答1:


  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




回答2:


This is also documented in GitLab online documentation : https://gitlab.com/help/user/project/merge_requests/index.md#checkout-merge-requests-locally

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.




回答3:


You can also add the line

fetch = +refs/merge-requests/*/head:refs/remotes/origin/merge-requests/*

to your .git/config to have git fetch fetch all merge requests.



来源:https://stackoverflow.com/questions/44992512/git-how-to-checkout-merge-request-locally-and-create-new-local-branch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!