# Git fetch pull/merge requests

**URL:** <https://community.tmpdir.org/t/git-fetch-pull-merge-requests/605>\
**Category:** Tools\
**Created:** [August 24, 2022, 12:13pm UTC](https://community.tmpdir.org/t/git-fetch-pull-merge-requests/605 "2022-08-24T12:13:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bradfa](https://community.tmpdir.org/user_avatar/community.tmpdir.org/bradfa/32/85_2.png) [@bradfa](https://community.tmpdir.org/u/bradfa)\
**Post date:** [August 24, 2022, 12:13pm UTC](https://community.tmpdir.org/t/git-fetch-pull-merge-requests/605/1 "2022-08-24T12:13:46Z")

</div>

I can never remember the nuance between Github and Gitlab but often want to fetch and checkout a specific pull/merge request when reviewing code. Why they need to implement this feature subtly different is beyond me, but alas.

On Github, to fetch a specific pull request, do:

```auto
git fetch $REMOTE +refs/pull/$PR_NUM/merge

```

On Gitlab, to fetch a specific merge request, do:

```auto
git fetch $REMOTE +refs/merge-requests/$MR_NUM/head

```

Then to checkout the just fetched ref, do:

```auto
git checkout FETCH_HEAD

```

You’ll end up in a detached HEAD state but the HEAD will be at the tip of the pull/merge request.

---

<div class="post-metadata">

**Author:** ![khem](https://community.tmpdir.org/user_avatar/community.tmpdir.org/khem/32/5_2.png) [@khem](https://community.tmpdir.org/u/khem)\
**Post date:** [August 24, 2022, 3:24pm UTC](https://community.tmpdir.org/t/git-fetch-pull-merge-requests/605/2 "2022-08-24T15:24:15Z")

</div>

With yoe distribution being on github I have bunch of repos to maintain on github. Here is what I use with github repos

in .git/config this is what I have

```auto
[remote "upstream"]
        url = https://github.com/openembedded/meta-openembedded
        fetch = +refs/heads/*:refs/remotes/upstream/*
        fetch = +refs/pull/*/head:refs/remotes/upstream/pr/*

```

so when I fetch I get them pulled under a namespace called `/pr`

```auto
% git fetch --all
Fetching upstream
remote: Enumerating objects: 10, done.
remote: Counting objects: 100% (10/10), done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 10 (delta 4), reused 10 (delta 4), pack-reused 0
Unpacking objects: 100% (10/10), 5.15 KiB | 1.72 MiB/s, done.
From https://github.com/openembedded/meta-openembedded
 + 03cb305dee...6d54ec022d master-next -> upstream/master-next (forced update)
 * [new ref] refs/pull/596/head -> upstream/pr/596

```

Then I can use this reference to stuff with PR e.g.

```auto
git checkout -b pr/596 upstream/pr/596

```

will create a local branch

```auto
git cherry-pick upstream/pr/596

```

is handy for single commits it will bring the patch from PR to my local integration branch  
and good thing is when I push my integration up into github it knows about the PR commits and can cross reference them.
