|
| 1 | +--- |
| 2 | +layout: page |
| 3 | +title: Contribute to someone's repository |
| 4 | +description: Git/GitHub Guide: contributing to someone's repository |
| 5 | +--- |
| 6 | + |
| 7 | +Say you want to contribute changes to someone else's repository (eg, |
| 8 | +[this one](http://github.com/kbroman/github_tutorial)). |
| 9 | + |
| 10 | +- Go to the repository on github. (Say it's by `myfriend`, and is |
| 11 | + called `the_repo`, then you'll find it at `http://github.com/myfriend/the_repo`.) |
| 12 | + |
| 13 | +- Click the “Fork” button at the top right. |
| 14 | + |
| 15 | +- You'll now have your own copy of that repository in your github account. |
| 16 | + |
| 17 | +- Open a terminal/shell. |
| 18 | + |
| 19 | +- Type |
| 20 | + |
| 21 | + $ git clone git@github.com:username/the_repo |
| 22 | + |
| 23 | + where `username` is _your_ username. |
| 24 | + |
| 25 | +- You'll now have a local copy of _your version_ of that repository. |
| 26 | + |
| 27 | +- Add a connection to the original owner's repository. |
| 28 | + |
| 29 | + $ git remote add myfriend git://github.com/myfriend/the_repo |
| 30 | + |
| 31 | +- Note the distinction between `git@github.com:` in the first case and |
| 32 | + `git://github.com/` in the second case. I'm not sure why these need |
| 33 | + to be the way they are, but that's what works for me. |
| 34 | + |
| 35 | +- Make changes to files. |
| 36 | + |
| 37 | +- `git add` and `git commit` those changes |
| 38 | + |
| 39 | +- `git push` them back to [github](http://github.com). These will go |
| 40 | + to _your version_ of the repository. |
| 41 | + |
| 42 | +- Go to _your version_ of the repository on github. |
| 43 | + |
| 44 | +- Click the “Pull Request” button at the top. |
| 45 | + |
| 46 | +- Note that your friend's repository will be on the left and _your |
| 47 | + repository_ will be on the right. |
| 48 | + |
| 49 | +- Give a short explaination of the changes and click the “Send |
| 50 | + pull request” button. |
| 51 | + |
| 52 | + |
| 53 | +### Pulling others' changes |
| 54 | + |
| 55 | +Before you make further changes to the repository, you should check |
| 56 | +that your version is up to date relative to your friend's version. |
| 57 | + |
| 58 | +Go into the directory for the project and type: |
| 59 | + |
| 60 | + $ git pull myfriend master |
| 61 | + |
| 62 | +This will pull down and merge all of the changes that your friend has |
| 63 | +made. |
| 64 | + |
| 65 | +Now push them back to your github repository. |
| 66 | + |
| 67 | + $ git push |
| 68 | + |
| 69 | + |
| 70 | +### Handling pull requests |
| 71 | + |
| 72 | +Say your friend has suggested some changes to your code. |
| 73 | + |
| 74 | +Ask them to [get a github account](first_use.html) and follow the |
| 75 | +instructions above: fork your |
| 76 | +repository, make the changes, and submit a pull request. |
| 77 | + |
| 78 | +Once they do that, you'll get an email about it. How to handle it? |
| 79 | + |
| 80 | +#### Using the github website: |
| 81 | + |
| 82 | +- Go to your version of the repository. |
| 83 | + |
| 84 | +- Click on “Pull Requests” at the top. |
| 85 | + |
| 86 | +- Click on the particular request. |
| 87 | + |
| 88 | +- You'll see their comments on the pull request, and can click to see |
| 89 | + the exact changes. |
| 90 | + |
| 91 | +- If you want them to make further changes before you merge |
| 92 | + the changes into your repository, add a comment. |
| 93 | + |
| 94 | +- If you hate the whole idea, just click the “Close” |
| 95 | + button. |
| 96 | + |
| 97 | +- If you want to merge the changes into your repository, click the |
| 98 | + “Merge pull request” button. |
| 99 | + |
| 100 | +- Your github repository will now be fixed, but you'll want to get |
| 101 | + them into your local repository, too. |
| 102 | + |
| 103 | +- Open a terminal/shell, and type |
| 104 | + |
| 105 | + $ git pull |
| 106 | + |
| 107 | +#### Using the command line |
| 108 | + |
| 109 | +You don't have to use the github website for this. |
| 110 | + |
| 111 | +- Open a terminal/shell. |
| 112 | + |
| 113 | +- Go into the directory for your project. |
| 114 | + |
| 115 | +- Add a connection to your friend's version of the github repository, |
| 116 | + if you haven't already. |
| 117 | + |
| 118 | + $ git remote add myfriend git://github.com/myfriend/the_repo |
| 119 | + |
| 120 | +- Pull his/her changes. |
| 121 | + |
| 122 | + $ git pull myfriend master |
| 123 | + |
| 124 | +- Push them back to your github repository. |
| 125 | + |
| 126 | + $ git push |
| 127 | + |
| 128 | +- The pull request on github will be automatically closed. |
| 129 | + |
| 130 | +**Next**: [Handling merge conflicts](merge_conflicts.html) |
0 commit comments