|
| 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 | +If you use Github Desktop or have the Github CLI installed, the simplest |
| 22 | +way to work on a fork is to click the **Code** dropdown on the PR's page |
| 23 | +on Github and checkout the PR from there. |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | +The instructions below are for command line use of git. |
| 28 | + |
| 29 | +1. **Before** you begin, confirm that your local main branch of Submitty is |
| 30 | + up-to-date. Additionally, if the PR's branch is not up-to-date with Submitty's main, |
| 31 | + there will be a button on its page on Github that you can press to update it. |
| 32 | + You may need to resolve merge conflicts in the process of updating it. |
| 33 | + |
| 34 | +  |
| 35 | + |
| 36 | +2. From the PR on the Github website, find the name of the |
| 37 | + user + branch name. It should be formatted something like this: |
| 38 | + ``` |
| 39 | + contributorusername:contributor_branch_name |
| 40 | + ``` |
| 41 | +
|
| 42 | + Additionally, find the name of the fork on the fork's page on Github. |
| 43 | + The `fork_name` may simply be `Submitty`, or the author may have chosen to another name. |
| 44 | + |
| 45 | +
|
| 46 | +3. Next, make a local branch on your computer in your working repository |
| 47 | + with the proposed code changes. Here are the command lines |
| 48 | + (substitute the user, branch, and fork names we found above): |
| 49 | +
|
| 50 | + If you **are not** using ssh keys on git: |
| 51 | + ``` |
| 52 | + git checkout -b contributorusername-contributor_branch_name main |
| 53 | + git pull https://github.com/contributorusername/fork_name.git contributor_branch_name |
| 54 | + ``` |
| 55 | + |
| 56 | + If you **are** using ssh keys on git: |
| 57 | + ``` |
| 58 | + git checkout -b contributorusername-contributor_branch_name main |
| 59 | + git pull [email protected]:contributorusername/fork_name.git contributor_branch_name |
| 60 | + ``` |
| 61 | +
|
| 62 | +
|
| 63 | +4. This has made a local branch named |
| 64 | + `contributorusername-contributor_branch_name`. Go ahead and test |
| 65 | + and review the PR and make code edits and new commits to your |
| 66 | + local branch as needed. |
| 67 | +
|
| 68 | +
|
| 69 | +
|
| 70 | +5. In order to push the changes to the contributor's fork (and the PR |
| 71 | + on Github from the fork), you will specify the upstream to be the |
| 72 | + contributor's fork: |
| 73 | +
|
| 74 | + If you **are not** using ssh keys on git: |
| 75 | + ``` |
| 76 | + git remote add upstream https://github.com/contributorusername/fork_name.git |
| 77 | + ``` |
| 78 | +
|
| 79 | +
|
| 80 | + If you **are** using ssh keys on git: |
| 81 | + ``` |
| 82 | + git remote add upstream [email protected]:contributorusername/fork_name.git |
| 83 | + ``` |
| 84 | +
|
| 85 | +
|
| 86 | + Confirm that the upstream was set: |
| 87 | + ``` |
| 88 | + git remote -v |
| 89 | + ``` |
| 90 | +
|
| 91 | + Which should print something like this if you **are not** using ssh keys on git: |
| 92 | + ``` |
| 93 | + origin https://github.com/Submitty/Submitty.git (fetch) |
| 94 | + origin https://github.com/Submitty/Submitty.git (push) |
| 95 | + upstream https://github.com/contributorusername/fork_name.git (fetch) |
| 96 | + upstream https://github.com/contributorusername/fork_name.git (push) |
| 97 | + ``` |
| 98 | +
|
| 99 | + Or this if you **are** using ssh keys on git: |
| 100 | + ``` |
| 101 | + origin [email protected]:Submitty/Submitty.git (fetch) |
| 102 | + origin [email protected]:Submitty/Submitty.git (push) |
| 103 | + upstream [email protected]:contributorusername/fork_name.git (fetch) |
| 104 | + upstream [email protected]:contributorusername/fork_name.git (push) |
| 105 | + ``` |
| 106 | +
|
| 107 | +
|
| 108 | +6. Now once you are finished with your code changes, first commit them to |
| 109 | + the local branch (named |
| 110 | + `contributorusername-contributor_branch_name`). |
| 111 | +
|
| 112 | + And then push them from your local branch to the external |
| 113 | + contributor's fork and update the PR on github: |
| 114 | + ``` |
| 115 | + git push upstream contributorusername-contributor_branch_name:contributor_branch_name |
| 116 | + ``` |
| 117 | +
|
| 118 | + *NOTE: If you encounter a permissions error, it is possible that the external |
| 119 | + contributor didn't grant access for collaboration on the branch.* |
| 120 | +
|
| 121 | +7. Confirm that you can see the changes on the Github website for the PR. |
| 122 | +
|
| 123 | +
|
| 124 | +--- |
| 125 | +
|
| 126 | +See also [How to Make a Pull Request](make_a_pull_request) and |
| 127 | +[How to Review a Pull Request](review_a_pull_request). |
0 commit comments