|
| 1 | +# Git Quickstart |
| 2 | + |
| 3 | +This tutorial serves as a quickstart to Git and contributing to our repository. If you have not already set up OpenROAD, please follow the instructions [here](../user/Build.md). |
| 4 | + |
| 5 | +```{tip} This basic tutorial gives instruction for basic password Git authentication. |
| 6 | +If you would like to setup SSH authentication, please follow this [guide](https://help.github.com/set-up-git-redirect). |
| 7 | +``` |
| 8 | + |
| 9 | +## Forking |
| 10 | + |
| 11 | +You will need your own fork to work on the code. Go to the `OpenROAD` project |
| 12 | +[page](https://github.com/The-OpenROAD-Project/OpenROAD) and hit the `Fork` button. You will |
| 13 | +want to clone your fork to your machine: |
| 14 | + |
| 15 | +```shell |
| 16 | +git clone https://github.com/your-user-name/OpenROAD.git |
| 17 | +cd OpenROAD |
| 18 | +git remote add upstream https://github.com/The-OpenROAD-Project/OpenROAD.git |
| 19 | +git fetch upstream |
| 20 | +``` |
| 21 | + |
| 22 | +This creates the directory `OpenROAD` and connects your repository to |
| 23 | +the upstream (master project) *OpenROAD* repository. |
| 24 | + |
| 25 | +## Creating a branch |
| 26 | + |
| 27 | +You want your master branch to reflect only production-ready code, so create a |
| 28 | +feature branch for making your changes. For example: |
| 29 | + |
| 30 | +```shell |
| 31 | +git checkout master && git branch shiny-new-feature |
| 32 | +git checkout shiny-new-feature |
| 33 | +# Or equivalently, |
| 34 | +git checkout master && git checkout -b shiny-new-feature |
| 35 | +``` |
| 36 | + |
| 37 | +This changes your working directory to the shiny-new-feature branch. Keep any |
| 38 | +changes in this branch specific to one bug or feature so it is clear |
| 39 | +what the branch brings to OpenROAD. You can have many shiny-new-features |
| 40 | +and switch in between them using the git checkout command. |
| 41 | + |
| 42 | +When creating this branch, make sure your master branch is up to date with |
| 43 | +the latest upstream master version. To update your local master branch, you |
| 44 | +can do: |
| 45 | + |
| 46 | +```shell |
| 47 | +git checkout master |
| 48 | +git pull upstream master |
| 49 | +``` |
| 50 | + |
| 51 | +When you want to update the feature branch with changes in master after |
| 52 | +you created the branch, check the section on |
| 53 | +[updating a PR](#updating-your-pull-request). |
| 54 | + |
| 55 | +## Committing your code |
| 56 | +Keep style fixes to a separate commit to make your pull request more readable. Once you've made changes, you can see them by typing: |
| 57 | + |
| 58 | +```shell |
| 59 | +git status |
| 60 | +``` |
| 61 | + |
| 62 | +If you have created a new file, it is not being tracked by git. Add it by typing: |
| 63 | +```shell |
| 64 | +git add path/to/file-to-be-added.py |
| 65 | +``` |
| 66 | + |
| 67 | +Doing `git status` again should give something like: |
| 68 | +```shell |
| 69 | +# On branch shiny-new-feature |
| 70 | +# |
| 71 | +# modified: /relative/path/to/file-you-added.py |
| 72 | +# |
| 73 | +``` |
| 74 | + |
| 75 | +Finally, commit your changes to your local repository with an explanatory commit |
| 76 | +message. Do note the `-s` option is needed for developer signoff. |
| 77 | +```shell |
| 78 | +git commit -s -m "your commit message goes here" |
| 79 | +``` |
| 80 | + |
| 81 | +## Pushing your changes |
| 82 | + |
| 83 | +When you want your changes to appear publicly on your GitHub page, push your |
| 84 | +forked feature branch's commits: |
| 85 | + |
| 86 | +```shell |
| 87 | +git push origin shiny-new-feature |
| 88 | +``` |
| 89 | + |
| 90 | +Here `origin` is the default name given to your remote repository on GitHub. |
| 91 | +You can see the remote repositories: |
| 92 | + |
| 93 | +```shell |
| 94 | +git remote -v |
| 95 | +``` |
| 96 | + |
| 97 | +If you added the upstream repository as described above you will see something |
| 98 | +like: |
| 99 | + |
| 100 | +```shell |
| 101 | +origin https://github.com/your-user-name/OpenROAD.git (fetch) |
| 102 | +origin https://github.com/your-user-name/OpenROAD.git (push) |
| 103 | +upstream https://github.com/The-OpenROAD-Project/OpenROAD.git (fetch) |
| 104 | +upstream https://github.com/The-OpenROAD-Project/OpenROAD.git (push) |
| 105 | +``` |
| 106 | + |
| 107 | +Now your code is on GitHub, but it is not yet a part of the OpenROAD project. For that to |
| 108 | +happen, a pull request needs to be submitted on GitHub. |
| 109 | + |
| 110 | +## Review your code |
| 111 | + |
| 112 | +When you're ready to ask for a code review, file a pull request. Before you do, once |
| 113 | +again make sure that you have followed all the guidelines outlined in the [Developer's Guide](./DeveloperGuide.md) |
| 114 | +regarding code style, tests, performance tests, and documentation. You should also |
| 115 | +double check your branch changes against the branch it was based on: |
| 116 | + |
| 117 | +1. Navigate to your repository on GitHub -- https://github.com/your-user-name/OpenROAD |
| 118 | +1. Click on `Branches` |
| 119 | +1. Click on the `Compare` button for your feature branch |
| 120 | +1. Select the `base` and `compare` branches, if necessary. This will be `master` and |
| 121 | + `shiny-new-feature`, respectively. |
| 122 | + |
| 123 | +## Submitting the pull request |
| 124 | + |
| 125 | +If everything looks good, you are ready to make a pull request. A pull request is how |
| 126 | +code from a local repository becomes available to the GitHub community and can be looked |
| 127 | +at and eventually merged into the master version. This pull request and its associated |
| 128 | +changes will eventually be committed to the master branch and available in the next |
| 129 | +release. To submit a pull request: |
| 130 | + |
| 131 | +1. Navigate to your repository on GitHub |
| 132 | +1. Click on the ``Compare & pull request`` button |
| 133 | +1. You can then click on ``Commits`` and ``Files Changed`` to make sure everything looks |
| 134 | + okay one last time |
| 135 | +1. Write a description of your changes in the ``Preview Discussion`` tab |
| 136 | +1. Click ``Send Pull Request``. |
| 137 | + |
| 138 | +This request then goes to the repository maintainers, and they will review |
| 139 | +the code. |
| 140 | + |
| 141 | +## Updating your pull request |
| 142 | + |
| 143 | +Based on the review you get on your pull request, you will probably need to make |
| 144 | +some changes to the code. In that case, you can make them in your branch, |
| 145 | +add a new commit to that branch, push it to GitHub, and the pull request will be |
| 146 | +automatically updated. Pushing them to GitHub again is done by: |
| 147 | + |
| 148 | +```shell |
| 149 | +git push origin shiny-new-feature |
| 150 | +``` |
| 151 | + |
| 152 | +This will automatically update your pull request with the latest code and restart the |
| 153 | +[Continuous Integration](./CI.md) tests. |
| 154 | + |
| 155 | +Another reason you might need to update your pull request is to solve conflicts |
| 156 | +with changes that have been merged into the master branch since you opened your |
| 157 | +pull request. |
| 158 | + |
| 159 | +To do this, you need to `merge upstream master` in your branch: |
| 160 | + |
| 161 | +```shell |
| 162 | +git checkout shiny-new-feature |
| 163 | +git fetch upstream |
| 164 | +git merge upstream/master |
| 165 | +``` |
| 166 | + |
| 167 | +If there are no conflicts (or they could be fixed automatically), a file with a |
| 168 | +default commit message will open, and you can simply save and quit this file. |
| 169 | + |
| 170 | +If there are merge conflicts, you need to solve those conflicts. See |
| 171 | +this [article](https://help.github.com/articles/resolving-a-merge-conflict-using-the-command-line/) |
| 172 | +for an explanation on how to do this. |
| 173 | +Once the conflicts are merged and the files where the conflicts were solved are |
| 174 | +added, you can run ``git commit`` to save those fixes. |
| 175 | + |
| 176 | +If you have uncommitted changes at the moment you want to update the branch with |
| 177 | +master, you will need to ``stash`` them prior to updating. |
| 178 | + |
| 179 | +```{seealso} |
| 180 | +See the stash [docs](https://git-scm.com/book/en/v2/Git-Tools-Stashing-and-Cleaning). |
| 181 | +``` |
| 182 | +This will effectively store your changes and they can be reapplied after updating. |
| 183 | + |
| 184 | +After the feature branch has been updated locally, you can now update your pull |
| 185 | +request by pushing to the branch on GitHub: |
| 186 | + |
| 187 | +```shell |
| 188 | +git push origin shiny-new-feature |
| 189 | +``` |
| 190 | + |
| 191 | +## Tips for a successful pull request |
| 192 | + |
| 193 | +If you have made it to the `Review your code` phase, one of the core contributors may |
| 194 | +take a look. Please note however that a handful of people are responsible for reviewing |
| 195 | +all of the contributions, which can often lead to bottlenecks. |
| 196 | + |
| 197 | +To improve the chances of your pull request being reviewed, you should: |
| 198 | + |
| 199 | +- **Reference an open issue** for non-trivial changes to clarify the PR's purpose |
| 200 | +- **Ensure you have appropriate tests**. These should be the first part of any PR |
| 201 | +- **Keep your pull requests as simple as possible**. Larger PRs take longer to review |
| 202 | +- **Ensure that CI is in a green state**. Reviewers may not even look otherwise |
| 203 | +- **Keep updating your pull request**, either by request or every few days |
| 204 | + |
| 205 | +## Acknowledgements |
| 206 | + |
| 207 | +This page has been adapted from [pandas Developer Guide](https://pandas.pydata.org/docs/development/contributing.html). |
0 commit comments