From eff3c35410e97d4238ef93816e5164884c8b1369 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Mon, 22 Aug 2016 19:57:43 +0000 Subject: Update merge_requests.md with a simpler way to check out a merge request The previous way was put under the "By modifying `.git/config` for a given repository" section. The disadvantage is that one has to modify `.git/config` for each repository that one uses. The new way was put under the "By adding a git alias" section. One has to create this git alias once, and then it will work from any repository, without having to modify `.git/config` over and over again. --- doc/workflow/merge_requests.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'doc/workflow') diff --git a/doc/workflow/merge_requests.md b/doc/workflow/merge_requests.md index d2ec56e6504..12ffa916a8f 100644 --- a/doc/workflow/merge_requests.md +++ b/doc/workflow/merge_requests.md @@ -15,6 +15,21 @@ Please note that you need to have builds configured to enable this feature. ## Checkout merge requests locally +### By adding a git alias + +Add the following alias to your `~/.gitconfig`: +``` +[alias] + mr = !sh -c 'git fetch origin merge-requests/$1/head:mr-$1 && git checkout mr-$1' - +``` +Now you can check out a particular merge request from any repository (it will use the `origin` remote) by: +``` +$ git mr 5 +``` +This will fetch the merge request into a local `mr-5` branch and check it out. + +### By modifying `.git/config` for a given repository + Locate the section for your GitLab remote in the `.git/config` file. It looks like this: ``` -- cgit v1.2.1 From d1ed0c76ec7e9ef4ec1ccff2756433997b3a2397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Tue, 23 Aug 2016 13:02:16 -0600 Subject: Add new lines after backticks and colons --- doc/workflow/merge_requests.md | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'doc/workflow') diff --git a/doc/workflow/merge_requests.md b/doc/workflow/merge_requests.md index 12ffa916a8f..adee26f0fe9 100644 --- a/doc/workflow/merge_requests.md +++ b/doc/workflow/merge_requests.md @@ -18,14 +18,18 @@ Please note that you need to have builds configured to enable this feature. ### By adding a git alias Add the following alias to your `~/.gitconfig`: + ``` [alias] mr = !sh -c 'git fetch origin merge-requests/$1/head:mr-$1 && git checkout mr-$1' - ``` + Now you can check out a particular merge request from any repository (it will use the `origin` remote) by: + ``` $ git mr 5 ``` + This will fetch the merge request into a local `mr-5` branch and check it out. ### By modifying `.git/config` for a given repository -- cgit v1.2.1 From a7bd1c23dd03f00d10b0ff4db655690283e2f88a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Tue, 23 Aug 2016 13:05:34 -0600 Subject: Modify the alias to allow specifying a remote Now the alias should be used as: git mr upstream 5 To check out a MR number 5 from the upstream remote, into a `mr-upstream-5` local branch. Also clarify that the `5` in the merge request is the number shown in GitLab. --- doc/workflow/merge_requests.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'doc/workflow') diff --git a/doc/workflow/merge_requests.md b/doc/workflow/merge_requests.md index adee26f0fe9..91fcfb02d39 100644 --- a/doc/workflow/merge_requests.md +++ b/doc/workflow/merge_requests.md @@ -21,16 +21,16 @@ Add the following alias to your `~/.gitconfig`: ``` [alias] - mr = !sh -c 'git fetch origin merge-requests/$1/head:mr-$1 && git checkout mr-$1' - + mr = !sh -c 'git fetch $1 merge-requests/$2/head:mr-$1-$2 && git checkout mr-$1-$2' - ``` -Now you can check out a particular merge request from any repository (it will use the `origin` remote) by: +Now you can check out a particular merge request from any repository and any remote, e.g. to check out a merge request number 5 as shown in GitLab from the `upstream` remote, do: ``` -$ git mr 5 +$ git mr upstream 5 ``` -This will fetch the merge request into a local `mr-5` branch and check it out. +This will fetch the merge request into a local `mr-upstream-5` branch and check it out. ### By modifying `.git/config` for a given repository -- cgit v1.2.1