|
| 1 | += Git and GitHub Fundamentals for Open-Source Contributions |
| 2 | + |
| 3 | +== What is Git? |
| 4 | +*Git* is an open-source version control system commonly used to make it easier for |
| 5 | +developers to introduce changes to a project without stepping on each others' toes. |
| 6 | +Git will track changes to files across time in the form of *commits*. |
| 7 | + |
| 8 | +A commit contains: |
| 9 | +- Code changes (referred to as the "commit diff") |
| 10 | +- Author/Timestamp information |
| 11 | +- A developer-written message describing the code changes |
| 12 | + |
| 13 | +Commits are made on *branches*. Branches allow developers to compartmentalize code |
| 14 | +changes by particular features, bug fixes, documentation updates, etc. Branches |
| 15 | +can be merged into other branches, allowing for developers to work on things |
| 16 | +at the same time while minimizing conflicts created by simultaneous work. |
| 17 | + |
| 18 | +All of these branches live inside of a Git *repository*, which is the collection |
| 19 | +of all branches and commits relevant to a Git project. |
| 20 | + |
| 21 | +== What is GitHub? |
| 22 | +*Github*, not to be confused with Git itself, is a Git repository hosting service |
| 23 | +commonly used by open-source projects, as Github provides free hosting for public |
| 24 | +and private repositories alike. It is leveraged by Decomp Toolkit Template projects |
| 25 | +to run Github Actions, which can be used to automate things like progress website |
| 26 | +updates and create Discord notifications when people contribute to a project. |
| 27 | + |
| 28 | +== Setting Up Git |
| 29 | + |
| 30 | +#link("https://docs.github.com/en/get-started/git-basics/set-up-git")[#underline("Here is a link to a guide")] |
| 31 | +hosted by Github is a great place to start for setting up and configuring Git. Follow it and |
| 32 | +you'll be able to set up Git locally on your machine! |
| 33 | + |
| 34 | +== Forking a Repository on GitHub |
| 35 | +#link("https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/fork-a-repo")[#underline("Here is a link to a guide")] |
| 36 | +provided by GitHub which is helpful for understanding repository forks, why they're useful, and how to work with them depending on your |
| 37 | +operating system (Windows, Mac, Linux). |
| 38 | + |
| 39 | +Check out the guide for step-by-steps instructions on how to: |
| 40 | +- Create a Github repository fork |
| 41 | +- Clone that repository fork |
| 42 | +- Configure your fork to be able to pull changes from the "upstream" original repository |
| 43 | + |
| 44 | +== Creating a Pull Request (PR) |
| 45 | + |
| 46 | +A pull request is a method by which you can propose the merging of your code changes into |
| 47 | +the original repository from your fork. |
| 48 | + |
| 49 | +#link("https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork")[#underline("Here is a link to a guide")] |
| 50 | +hosted by GitHub which will show you how to create a pull request once you've pushed changes to your remote fork. |
| 51 | +It will take you step-by-step through the pull request creation process. |
| 52 | + |
| 53 | +Your pull request should contain: |
| 54 | +- A descriptive summary of your proposed changes contained in the PR |
| 55 | +- A helpful description which goes into detail about what changes you made and why you did them as needed |
| 56 | + |
| 57 | +== Responding to PR Reviews |
| 58 | + |
| 59 | +Once you've opened a pull request, you're not done yet! There's still some steps that |
| 60 | +will happen before your code is merged into the original project repository: |
| 61 | +- A maintainer will review your pull request |
| 62 | +- The maintainers may post comments to discuss your changes with you |
| 63 | +- The maintainers may request code changes they would like to see to better align your code with project standards |
| 64 | + |
| 65 | +Engage with the project maintainers on your pull request, pushing changes to your code as needed |
| 66 | +until all feedback is addressed. Don't worry about updating your pull request on GitHub - |
| 67 | +pushing changes to your fork branch will automatically update the pull request for you. |
| 68 | + |
| 69 | +Once all of the feedback has been addressed, the maintainers will merge your changes |
| 70 | +into the project repository. Congratulations - you're now a contributor to open source, and hopefully |
| 71 | +the newest contributor to the BfBB Decomp project! |
| 72 | + |
| 73 | +== Github Command Quick Reference |
| 74 | + |
| 75 | +This section is intended to serve as a quick reference for some common Git workflows |
| 76 | +that you will use while working on your project. The documentation here is provided for |
| 77 | +the Git command line interface - you will have to reference the particular documentation |
| 78 | +for your GUI client (Github Desktop, etc.) to determine how to perform these actions using |
| 79 | +your GUI of choice. |
| 80 | + |
| 81 | +=== Creating and Checking Out Branches |
| 82 | +Branches are used to isolate development of particular features or bugs into |
| 83 | +compartmentalized units. |
| 84 | + |
| 85 | +To checkout a new branch `my_branch` using the `main` branch as a base: |
| 86 | +``` |
| 87 | +git checkout main |
| 88 | +git checkout -b my_branch |
| 89 | +``` |
| 90 | + |
| 91 | +To checkout an existing branch `my_branch`: |
| 92 | +``` |
| 93 | +git checkout my_branch |
| 94 | +``` |
| 95 | + |
| 96 | +To delete a branch `my_branch` (*Note: This will delete any unmerged changes for good! Be careful!*): |
| 97 | +``` |
| 98 | +git branch -D my_branch |
| 99 | +``` |
| 100 | + |
| 101 | +=== Making Changes and Committing |
| 102 | + |
| 103 | +Files must be staged before the changes contained in those files can be committed. |
| 104 | + |
| 105 | +To stage an individual file: |
| 106 | +``` |
| 107 | +git add path/to/my/file |
| 108 | +``` |
| 109 | + |
| 110 | +To stage all tracked files: |
| 111 | +``` |
| 112 | +git add -u |
| 113 | +git status |
| 114 | +``` |
| 115 | +`git status` is optional but it can be a good sanity check to make sure that the files |
| 116 | +you intended to stage are staged and no files you did not intend to stage are staged. |
| 117 | + |
| 118 | +To commit staged changes: |
| 119 | +``` |
| 120 | +git commit -m "<commit message>" |
| 121 | +``` |
| 122 | +A good commit message should: |
| 123 | +- Contain a message summary no longer than 72 characters |
| 124 | +- Describe what changes are made by the commit |
| 125 | +- Explain any decisions or limitations contained in the changes (if the commit contains complex changes) |
| 126 | + |
| 127 | +A good example commit for the BfBB Decomp project follows the format: |
| 128 | +``` |
| 129 | +<decompiled filename>: <change to file> |
| 130 | +``` |
| 131 | + |
| 132 | +Some examples of good commit messages: |
| 133 | +``` |
| 134 | +zCamera: Matches for zCameraFlyRestoreBackup and zCameraRewardUpdate functions |
| 135 | + |
| 136 | +zNPCGoalAmbient: zNPCGoalJellyBumped Near 100% Match |
| 137 | + |
| 138 | +iTRC: Data Updates and Matches for Font Rendering Functions |
| 139 | +``` |
| 140 | + |
| 141 | +=== Pushing Changes to Your Fork |
| 142 | +To push changes from your local repository to your remote fork repository and configure tracking for that branch: |
| 143 | +``` |
| 144 | +git push -u origin my_branch |
| 145 | +``` |
| 146 | + |
| 147 | +To push changes from your local repository to your remote fork repository after configuring tracking: |
| 148 | +``` |
| 149 | +git push |
| 150 | +``` |
| 151 | + |
| 152 | +=== Integrating Upstream Changes into your Fork |
| 153 | +When the upstream main branch is updated, and you want to integrate those changes |
| 154 | +into your working branch `my_branch` by rebase (*recommended*): |
| 155 | +``` |
| 156 | +git stash |
| 157 | +git checkout main |
| 158 | +git pull |
| 159 | +git checkout my_branch |
| 160 | +git rebase main |
| 161 | +git stash apply |
| 162 | +``` |
| 163 | + |
| 164 | +When the upstream main branch is updated, and you want to integrate those changes |
| 165 | +into your working branch `my_branch` by merge (*not* recommended): |
| 166 | +``` |
| 167 | +git stash |
| 168 | +git checkout main |
| 169 | +git pull |
| 170 | +git checkout my_branch |
| 171 | +git merge main |
| 172 | +git stash apply |
| 173 | +``` |
0 commit comments