1(mr_fork)= 2 3# Checkout fork merge request branch 4 5`Developers` at times, need to checkout and build changes from a merge request fork branch. Any one of the following methods can be used: 6 7- Checkout `COMMIT-SHA` of the branch HEAD. It is available on the "Commits" tab of the merge request web page. 8 9 ```console 10 % git fetch origin <COMMIT-SHA> 11 % git checkout FETCH_HEAD 12 ``` 13 14- Checkout branch using the repository `URL`. The `URL with branchname` is available as "Source branch" hyperlink on merge request web page. 15 16 ```console 17 % git fetch <URL> <branchname> 18 % git checkout FETCH_HEAD 19 ``` 20 21- Setup a local Git clone to access the merge request branch via the `MR-NUMBER`. Here use the following in `.git/config`: 22 23 ```console 24 [remote "origin"] 25 url = https://gitlab.com/petsc/petsc.git 26 pushurl = git@gitlab.com:petsc/petsc.git 27 fetch = +refs/heads/*:refs/remotes/origin/* 28 fetch = +refs/merge-requests/*:refs/remotes/origin/merge-requests/* 29 ``` 30 31 Now, the branch is available to checkout: 32 33 ```console 34 % git fetch 35 % git checkout origin/merge-requests/<MR-NUMBER>/head 36 ``` 37 38# Commit and push changes to a merge request fork branch 39 40Only `Owners/Maintainers` can push commits to a merge request fork branch. Here, use the `ssh-URL` for the Git repository. 41 42```console 43% git fetch <ssh-URL> <branchname> 44% git checkout -b <branchname> FETCH_HEAD 45% git push -u <ssh-URL> <branchname> 46% (edit/commit) 47% git push 48``` 49 50Notes: 51 52For example, with `merge request` at <https://gitlab.com/petsc/petsc/-/merge_requests/8619> we have: 53 54- `MR-NUMBER` = `8619` 55- `COMMIT-SHA` = `1b741c341f10772b6231f15a4abcef052bfe2d90` ("Copy commit SHA" of the HEAD commit from the "Commits" tab) 56- `URL with branchname` = `https://gitlab.com/paul.kuehner/petsc/-/tree/add-tao-get-constraints` ("Copy link" of "Source branch") 57- `URL` = `https://gitlab.com/paul.kuehner/petsc` 58- `ssh-URL` = `git@gitlab.com:paul.kuehner/petsc.git` 59- `branchname` = `add-tao-get-constraints` 60 61