|
| 1 | +--- |
| 2 | +title: How To Checkout and Commit to a PR from a Forked Repository |
| 3 | +category: Developer > Getting Started |
| 4 | +--- |
| 5 | + |
| 6 | +Contributors who are part of the Submitty organization on Github can |
| 7 | +make new branches on our Github repositories and should make PRs from |
| 8 | +a *branch directly within the Submitty repository*. External |
| 9 | +contributors cannot make new branches on the Submitty repositories. |
| 10 | +Instead, external contributors will clone/fork the Submitty repository |
| 11 | +and then make a PR from *a branch on their forked repository*. |
| 12 | + |
| 13 | +It is simpler to review a PR made from a branch, and it is easy to |
| 14 | +make small revisions as needed and commit and push those changes to |
| 15 | +the branch. It is a little more work to do the same with a PR made |
| 16 | +from a fork, but it is still possible -- *assuming that the owner of |
| 17 | +the forked repository has granted the necessary permissions*. This |
| 18 | +allows multiple developers to collaborate and finalize a PR for |
| 19 | +merging to the main branch. |
| 20 | + |
| 21 | +The instructions below are for command line use of git. |
| 22 | + |
| 23 | + |
| 24 | +1. First, from the PR on the Github website, find the name of the |
| 25 | + fork + branch name. It should be formatted something like this: |
| 26 | + ``` |
| 27 | + contributorusername:contributor_branch_name |
| 28 | + ``` |
| 29 | +
|
| 30 | +
|
| 31 | +2. Next, make a local branch on your computer in your working repository |
| 32 | + with the proposed code changes. Here are the command lines |
| 33 | + (substitute the fork & branch name we found above): |
| 34 | +
|
| 35 | + If you **are not** using ssh keys on git: |
| 36 | + ``` |
| 37 | + git checkout -b contributorusername-contributor_branch_name main |
| 38 | + git pull https://github.com/contributorusername/Submitty.git contributor_branch_name |
| 39 | + ``` |
| 40 | + |
| 41 | + If you **are** using ssh keys on git: |
| 42 | + ``` |
| 43 | + git checkout -b contributorusername-contributor_branch_name main |
| 44 | + git pull [email protected]:contributorusername/Submitty.git contributor_branch_name |
| 45 | + ``` |
| 46 | +
|
| 47 | +
|
| 48 | +3. This has made a local branch named |
| 49 | + `contributorusername-contributor_branch_name`. Go ahead and test |
| 50 | + and review the PR and make code edits and new commits to your |
| 51 | + local branch as needed. |
| 52 | +
|
| 53 | +
|
| 54 | +
|
| 55 | +4. In order to push the changes to the contributor's fork (and the PR |
| 56 | + on Github from the fork), you will specify the upstream to be the |
| 57 | + contributor's fork: |
| 58 | +
|
| 59 | + If you **are not** using ssh keys on git: |
| 60 | + ``` |
| 61 | + git remote add upstream https://github.com/contributorusername/Submitty.git |
| 62 | + ``` |
| 63 | +
|
| 64 | +
|
| 65 | + If you **are** using ssh keys on git: |
| 66 | + ``` |
| 67 | + git remote add upstream [email protected]:contributorusername/Submitty.git |
| 68 | + ``` |
| 69 | +
|
| 70 | +
|
| 71 | + Confirm that the upstream was set: |
| 72 | + ``` |
| 73 | + git remote -v |
| 74 | + ``` |
| 75 | +
|
| 76 | + Which should print something like this if you **are not** using ssh keys on git: |
| 77 | + ``` |
| 78 | + origin https://github.com/Submitty/Submitty.git (fetch) |
| 79 | + origin https://github.com/Submitty/Submitty.git (push) |
| 80 | + upstream https://github.com/contributorusername/Submitty.git (fetch) |
| 81 | + upstream https://github.com/contributorusername/Submitty.git (push) |
| 82 | + ``` |
| 83 | +
|
| 84 | + Or this if you **are** using ssh keys on git: |
| 85 | + ``` |
| 86 | + origin [email protected]:Submitty/Submitty.git (fetch) |
| 87 | + origin [email protected]:Submitty/Submitty.git (push) |
| 88 | + upstream [email protected]:contributorusername/Submitty.git (fetch) |
| 89 | + upstream [email protected]:contributorusername/Submitty.git (push) |
| 90 | + ``` |
| 91 | +
|
| 92 | +
|
| 93 | +5. Now once you are finished with your code changes, first commit them to |
| 94 | + the local branch (named |
| 95 | + `contributorusername-contributor_branch_name`). |
| 96 | +
|
| 97 | + And then push them from your local branch to the external |
| 98 | + contributor's fork and update the PR on github: |
| 99 | + ``` |
| 100 | + git push upstream contributorusername-contributor_branch_name:contributor_branch_name |
| 101 | + ``` |
| 102 | +
|
| 103 | + *NOTE: If you encounter a permissions error, it is possible that the external |
| 104 | + contributor didn't grant access for collaboration on the branch.* |
| 105 | +
|
| 106 | +6. Confirm that you can see the changes on the Github website for the PR. |
| 107 | +
|
| 108 | +
|
| 109 | +--- |
| 110 | +
|
| 111 | +See also [How to Make a Pull Request](make_a_pull_request) and |
| 112 | +[How to Review a Pull Request](review_a_pull_request). |
0 commit comments