├── LICENSE └── README.md /LICENSE: -------------------------------------------------------------------------------- 1 | Attribution-ShareAlike 4.0 International 2 | 3 | ======================================================================= 4 | 5 | Creative Commons Corporation ("Creative Commons") is not a law firm and 6 | does not provide legal services or legal advice. Distribution of 7 | Creative Commons public licenses does not create a lawyer-client or 8 | other relationship. Creative Commons makes its licenses and related 9 | information available on an "as-is" basis. Creative Commons gives no 10 | warranties regarding its licenses, any material licensed under their 11 | terms and conditions, or any related information. Creative Commons 12 | disclaims all liability for damages resulting from their use to the 13 | fullest extent possible. 14 | 15 | Using Creative Commons Public Licenses 16 | 17 | Creative Commons public licenses provide a standard set of terms and 18 | conditions that creators and other rights holders may use to share 19 | original works of authorship and other material subject to copyright 20 | and certain other rights specified in the public license below. The 21 | following considerations are for informational purposes only, are not 22 | exhaustive, and do not form part of our licenses. 23 | 24 | Considerations for licensors: Our public licenses are 25 | intended for use by those authorized to give the public 26 | permission to use material in ways otherwise restricted by 27 | copyright and certain other rights. Our licenses are 28 | irrevocable. Licensors should read and understand the terms 29 | and conditions of the license they choose before applying it. 30 | Licensors should also secure all rights necessary before 31 | applying our licenses so that the public can reuse the 32 | material as expected. Licensors should clearly mark any 33 | material not subject to the license. This includes other CC- 34 | licensed material, or material used under an exception or 35 | limitation to copyright. More considerations for licensors: 36 | wiki.creativecommons.org/Considerations_for_licensors 37 | 38 | Considerations for the public: By using one of our public 39 | licenses, a licensor grants the public permission to use the 40 | licensed material under specified terms and conditions. If 41 | the licensor's permission is not necessary for any reason--for 42 | example, because of any applicable exception or limitation to 43 | copyright--then that use is not regulated by the license. Our 44 | licenses grant only permissions under copyright and certain 45 | other rights that a licensor has authority to grant. Use of 46 | the licensed material may still be restricted for other 47 | reasons, including because others have copyright or other 48 | rights in the material. A licensor may make special requests, 49 | such as asking that all changes be marked or described. 50 | Although not required by our licenses, you are encouraged to 51 | respect those requests where reasonable. More_considerations 52 | for the public: 53 | wiki.creativecommons.org/Considerations_for_licensees 54 | 55 | ======================================================================= 56 | 57 | Creative Commons Attribution-ShareAlike 4.0 International Public 58 | License 59 | 60 | By exercising the Licensed Rights (defined below), You accept and agree 61 | to be bound by the terms and conditions of this Creative Commons 62 | Attribution-ShareAlike 4.0 International Public License ("Public 63 | License"). To the extent this Public License may be interpreted as a 64 | contract, You are granted the Licensed Rights in consideration of Your 65 | acceptance of these terms and conditions, and the Licensor grants You 66 | such rights in consideration of benefits the Licensor receives from 67 | making the Licensed Material available under these terms and 68 | conditions. 69 | 70 | 71 | Section 1 -- Definitions. 72 | 73 | a. Adapted Material means material subject to Copyright and Similar 74 | Rights that is derived from or based upon the Licensed Material 75 | and in which the Licensed Material is translated, altered, 76 | arranged, transformed, or otherwise modified in a manner requiring 77 | permission under the Copyright and Similar Rights held by the 78 | Licensor. For purposes of this Public License, where the Licensed 79 | Material is a musical work, performance, or sound recording, 80 | Adapted Material is always produced where the Licensed Material is 81 | synched in timed relation with a moving image. 82 | 83 | b. Adapter's License means the license You apply to Your Copyright 84 | and Similar Rights in Your contributions to Adapted Material in 85 | accordance with the terms and conditions of this Public License. 86 | 87 | c. BY-SA Compatible License means a license listed at 88 | creativecommons.org/compatiblelicenses, approved by Creative 89 | Commons as essentially the equivalent of this Public License. 90 | 91 | d. Copyright and Similar Rights means copyright and/or similar rights 92 | closely related to copyright including, without limitation, 93 | performance, broadcast, sound recording, and Sui Generis Database 94 | Rights, without regard to how the rights are labeled or 95 | categorized. For purposes of this Public License, the rights 96 | specified in Section 2(b)(1)-(2) are not Copyright and Similar 97 | Rights. 98 | 99 | e. Effective Technological Measures means those measures that, in the 100 | absence of proper authority, may not be circumvented under laws 101 | fulfilling obligations under Article 11 of the WIPO Copyright 102 | Treaty adopted on December 20, 1996, and/or similar international 103 | agreements. 104 | 105 | f. Exceptions and Limitations means fair use, fair dealing, and/or 106 | any other exception or limitation to Copyright and Similar Rights 107 | that applies to Your use of the Licensed Material. 108 | 109 | g. License Elements means the license attributes listed in the name 110 | of a Creative Commons Public License. The License Elements of this 111 | Public License are Attribution and ShareAlike. 112 | 113 | h. Licensed Material means the artistic or literary work, database, 114 | or other material to which the Licensor applied this Public 115 | License. 116 | 117 | i. Licensed Rights means the rights granted to You subject to the 118 | terms and conditions of this Public License, which are limited to 119 | all Copyright and Similar Rights that apply to Your use of the 120 | Licensed Material and that the Licensor has authority to license. 121 | 122 | j. Licensor means the individual(s) or entity(ies) granting rights 123 | under this Public License. 124 | 125 | k. Share means to provide material to the public by any means or 126 | process that requires permission under the Licensed Rights, such 127 | as reproduction, public display, public performance, distribution, 128 | dissemination, communication, or importation, and to make material 129 | available to the public including in ways that members of the 130 | public may access the material from a place and at a time 131 | individually chosen by them. 132 | 133 | l. Sui Generis Database Rights means rights other than copyright 134 | resulting from Directive 96/9/EC of the European Parliament and of 135 | the Council of 11 March 1996 on the legal protection of databases, 136 | as amended and/or succeeded, as well as other essentially 137 | equivalent rights anywhere in the world. 138 | 139 | m. You means the individual or entity exercising the Licensed Rights 140 | under this Public License. Your has a corresponding meaning. 141 | 142 | 143 | Section 2 -- Scope. 144 | 145 | a. License grant. 146 | 147 | 1. Subject to the terms and conditions of this Public License, 148 | the Licensor hereby grants You a worldwide, royalty-free, 149 | non-sublicensable, non-exclusive, irrevocable license to 150 | exercise the Licensed Rights in the Licensed Material to: 151 | 152 | a. reproduce and Share the Licensed Material, in whole or 153 | in part; and 154 | 155 | b. produce, reproduce, and Share Adapted Material. 156 | 157 | 2. Exceptions and Limitations. For the avoidance of doubt, where 158 | Exceptions and Limitations apply to Your use, this Public 159 | License does not apply, and You do not need to comply with 160 | its terms and conditions. 161 | 162 | 3. Term. The term of this Public License is specified in Section 163 | 6(a). 164 | 165 | 4. Media and formats; technical modifications allowed. The 166 | Licensor authorizes You to exercise the Licensed Rights in 167 | all media and formats whether now known or hereafter created, 168 | and to make technical modifications necessary to do so. The 169 | Licensor waives and/or agrees not to assert any right or 170 | authority to forbid You from making technical modifications 171 | necessary to exercise the Licensed Rights, including 172 | technical modifications necessary to circumvent Effective 173 | Technological Measures. For purposes of this Public License, 174 | simply making modifications authorized by this Section 2(a) 175 | (4) never produces Adapted Material. 176 | 177 | 5. Downstream recipients. 178 | 179 | a. Offer from the Licensor -- Licensed Material. Every 180 | recipient of the Licensed Material automatically 181 | receives an offer from the Licensor to exercise the 182 | Licensed Rights under the terms and conditions of this 183 | Public License. 184 | 185 | b. Additional offer from the Licensor -- Adapted Material. 186 | Every recipient of Adapted Material from You 187 | automatically receives an offer from the Licensor to 188 | exercise the Licensed Rights in the Adapted Material 189 | under the conditions of the Adapter's License You apply. 190 | 191 | c. No downstream restrictions. You may not offer or impose 192 | any additional or different terms or conditions on, or 193 | apply any Effective Technological Measures to, the 194 | Licensed Material if doing so restricts exercise of the 195 | Licensed Rights by any recipient of the Licensed 196 | Material. 197 | 198 | 6. No endorsement. Nothing in this Public License constitutes or 199 | may be construed as permission to assert or imply that You 200 | are, or that Your use of the Licensed Material is, connected 201 | with, or sponsored, endorsed, or granted official status by, 202 | the Licensor or others designated to receive attribution as 203 | provided in Section 3(a)(1)(A)(i). 204 | 205 | b. Other rights. 206 | 207 | 1. Moral rights, such as the right of integrity, are not 208 | licensed under this Public License, nor are publicity, 209 | privacy, and/or other similar personality rights; however, to 210 | the extent possible, the Licensor waives and/or agrees not to 211 | assert any such rights held by the Licensor to the limited 212 | extent necessary to allow You to exercise the Licensed 213 | Rights, but not otherwise. 214 | 215 | 2. Patent and trademark rights are not licensed under this 216 | Public License. 217 | 218 | 3. To the extent possible, the Licensor waives any right to 219 | collect royalties from You for the exercise of the Licensed 220 | Rights, whether directly or through a collecting society 221 | under any voluntary or waivable statutory or compulsory 222 | licensing scheme. In all other cases the Licensor expressly 223 | reserves any right to collect such royalties. 224 | 225 | 226 | Section 3 -- License Conditions. 227 | 228 | Your exercise of the Licensed Rights is expressly made subject to the 229 | following conditions. 230 | 231 | a. Attribution. 232 | 233 | 1. If You Share the Licensed Material (including in modified 234 | form), You must: 235 | 236 | a. retain the following if it is supplied by the Licensor 237 | with the Licensed Material: 238 | 239 | i. identification of the creator(s) of the Licensed 240 | Material and any others designated to receive 241 | attribution, in any reasonable manner requested by 242 | the Licensor (including by pseudonym if 243 | designated); 244 | 245 | ii. a copyright notice; 246 | 247 | iii. a notice that refers to this Public License; 248 | 249 | iv. a notice that refers to the disclaimer of 250 | warranties; 251 | 252 | v. a URI or hyperlink to the Licensed Material to the 253 | extent reasonably practicable; 254 | 255 | b. indicate if You modified the Licensed Material and 256 | retain an indication of any previous modifications; and 257 | 258 | c. indicate the Licensed Material is licensed under this 259 | Public License, and include the text of, or the URI or 260 | hyperlink to, this Public License. 261 | 262 | 2. You may satisfy the conditions in Section 3(a)(1) in any 263 | reasonable manner based on the medium, means, and context in 264 | which You Share the Licensed Material. For example, it may be 265 | reasonable to satisfy the conditions by providing a URI or 266 | hyperlink to a resource that includes the required 267 | information. 268 | 269 | 3. If requested by the Licensor, You must remove any of the 270 | information required by Section 3(a)(1)(A) to the extent 271 | reasonably practicable. 272 | 273 | b. ShareAlike. 274 | 275 | In addition to the conditions in Section 3(a), if You Share 276 | Adapted Material You produce, the following conditions also apply. 277 | 278 | 1. The Adapter's License You apply must be a Creative Commons 279 | license with the same License Elements, this version or 280 | later, or a BY-SA Compatible License. 281 | 282 | 2. You must include the text of, or the URI or hyperlink to, the 283 | Adapter's License You apply. You may satisfy this condition 284 | in any reasonable manner based on the medium, means, and 285 | context in which You Share Adapted Material. 286 | 287 | 3. You may not offer or impose any additional or different terms 288 | or conditions on, or apply any Effective Technological 289 | Measures to, Adapted Material that restrict exercise of the 290 | rights granted under the Adapter's License You apply. 291 | 292 | 293 | Section 4 -- Sui Generis Database Rights. 294 | 295 | Where the Licensed Rights include Sui Generis Database Rights that 296 | apply to Your use of the Licensed Material: 297 | 298 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right 299 | to extract, reuse, reproduce, and Share all or a substantial 300 | portion of the contents of the database; 301 | 302 | b. if You include all or a substantial portion of the database 303 | contents in a database in which You have Sui Generis Database 304 | Rights, then the database in which You have Sui Generis Database 305 | Rights (but not its individual contents) is Adapted Material, 306 | 307 | including for purposes of Section 3(b); and 308 | c. You must comply with the conditions in Section 3(a) if You Share 309 | all or a substantial portion of the contents of the database. 310 | 311 | For the avoidance of doubt, this Section 4 supplements and does not 312 | replace Your obligations under this Public License where the Licensed 313 | Rights include other Copyright and Similar Rights. 314 | 315 | 316 | Section 5 -- Disclaimer of Warranties and Limitation of Liability. 317 | 318 | a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE 319 | EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS 320 | AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF 321 | ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS, 322 | IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION, 323 | WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR 324 | PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS, 325 | ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT 326 | KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT 327 | ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU. 328 | 329 | b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE 330 | TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION, 331 | NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT, 332 | INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES, 333 | COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR 334 | USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN 335 | ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR 336 | DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR 337 | IN PART, THIS LIMITATION MAY NOT APPLY TO YOU. 338 | 339 | c. The disclaimer of warranties and limitation of liability provided 340 | above shall be interpreted in a manner that, to the extent 341 | possible, most closely approximates an absolute disclaimer and 342 | waiver of all liability. 343 | 344 | 345 | Section 6 -- Term and Termination. 346 | 347 | a. This Public License applies for the term of the Copyright and 348 | Similar Rights licensed here. However, if You fail to comply with 349 | this Public License, then Your rights under this Public License 350 | terminate automatically. 351 | 352 | b. Where Your right to use the Licensed Material has terminated under 353 | Section 6(a), it reinstates: 354 | 355 | 1. automatically as of the date the violation is cured, provided 356 | it is cured within 30 days of Your discovery of the 357 | violation; or 358 | 359 | 2. upon express reinstatement by the Licensor. 360 | 361 | For the avoidance of doubt, this Section 6(b) does not affect any 362 | right the Licensor may have to seek remedies for Your violations 363 | of this Public License. 364 | 365 | c. For the avoidance of doubt, the Licensor may also offer the 366 | Licensed Material under separate terms or conditions or stop 367 | distributing the Licensed Material at any time; however, doing so 368 | will not terminate this Public License. 369 | 370 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public 371 | License. 372 | 373 | 374 | Section 7 -- Other Terms and Conditions. 375 | 376 | a. The Licensor shall not be bound by any additional or different 377 | terms or conditions communicated by You unless expressly agreed. 378 | 379 | b. Any arrangements, understandings, or agreements regarding the 380 | Licensed Material not stated herein are separate from and 381 | independent of the terms and conditions of this Public License. 382 | 383 | 384 | Section 8 -- Interpretation. 385 | 386 | a. For the avoidance of doubt, this Public License does not, and 387 | shall not be interpreted to, reduce, limit, restrict, or impose 388 | conditions on any use of the Licensed Material that could lawfully 389 | be made without permission under this Public License. 390 | 391 | b. To the extent possible, if any provision of this Public License is 392 | deemed unenforceable, it shall be automatically reformed to the 393 | minimum extent necessary to make it enforceable. If the provision 394 | cannot be reformed, it shall be severed from this Public License 395 | without affecting the enforceability of the remaining terms and 396 | conditions. 397 | 398 | c. No term or condition of this Public License will be waived and no 399 | failure to comply consented to unless expressly agreed to by the 400 | Licensor. 401 | 402 | d. Nothing in this Public License constitutes or may be interpreted 403 | as a limitation upon, or waiver of, any privileges and immunities 404 | that apply to the Licensor or You, including from the legal 405 | processes of any jurisdiction or authority. 406 | 407 | 408 | ======================================================================= 409 | 410 | Creative Commons is not a party to its public 411 | licenses. Notwithstanding, Creative Commons may elect to apply one of 412 | its public licenses to material it publishes and in those instances 413 | will be considered the “Licensor.” The text of the Creative Commons 414 | public licenses is dedicated to the public domain under the CC0 Public 415 | Domain Dedication. Except for the limited purpose of indicating that 416 | material is shared under a Creative Commons public license or as 417 | otherwise permitted by the Creative Commons policies published at 418 | creativecommons.org/policies, Creative Commons does not authorize the 419 | use of the trademark "Creative Commons" or any other trademark or logo 420 | of Creative Commons without its prior written consent including, 421 | without limitation, in connection with any unauthorized modifications 422 | to any of its public licenses or any other arrangements, 423 | understandings, or agreements concerning use of licensed material. For 424 | the avoidance of doubt, this paragraph does not form part of the 425 | public licenses. 426 | 427 | Creative Commons may be contacted at creativecommons.org. 428 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Git and MicroPython 2 | 3 | [![CC BY-SA 4.0][cc-by-sa-shield]][cc-by-sa] 4 | 5 | A guide for using git with the [MicroPython project](https://github.com/micropython/micropython). 6 | The advice here is tailored specifically to the workflow used by the 7 | MicroPython project, but should apply generally to most projects that use git 8 | and GitHub. 9 | 10 | The advice here has been collected from personal experience of several years 11 | of working as a maintainer on the MicroPython project, and aims to address the 12 | common scenarios that contributors might run into. 13 | 14 | ## Status 15 | 16 | DRAFT. Currently this is a work in progress, many of the snippets have not 17 | been tested. 18 | 19 | Copyright © 2023 [Jim Mussared](https://github.com/jimmo) 20 | 21 | This work is licensed under a 22 | [Creative Commons Attribution-ShareAlike 4.0 International License][cc-by-sa]. 23 | 24 | [![CC BY-SA 4.0][cc-by-sa-image]][cc-by-sa] 25 | 26 | [cc-by-sa]: http://creativecommons.org/licenses/by-sa/4.0/ 27 | [cc-by-sa-image]: https://licensebuttons.net/l/by-sa/4.0/88x31.png 28 | [cc-by-sa-shield]: https://img.shields.io/badge/License-CC%20BY--SA%204.0-lightgrey.svg 29 | 30 | ## Contributing 31 | 32 | Please [raise an 33 | issue](https://github.com/jimmo/git-and-micropython/issues/new) if you have a 34 | scenario that isn't covered here, or if the advice here doesn't work for you. 35 | Please include as much information as possible, including commands that you 36 | have run and corresponding output. 37 | 38 | PRs are also most welcome! 39 | 40 | If you found this guide useful, please consider 41 | [sponsoring me](https://github.com/sponsors/jimmo/) or the 42 | [MicroPython project](https://github.com/sponsors/micropython/) on GitHub Sponsors. 43 | 44 | ## Quick notes 45 | 46 | * Don't use the GitHub Desktop tool, and prefer to use `git` directly rather 47 | than GitHub's `gh` client. These are good tools, but designed with a 48 | different workflow in mind. 49 | * It can however be very helpful to use a graphical git client for some 50 | operations. For example, I highly recommend 51 | [https://www.sublimemerge.com/](https://www.sublimemerge.com/) especially 52 | for working with merge/rebase conflicts, browsing the repo, creating 53 | commits, and in particular selectively stating files, hunks, or lines. It 54 | works very well in conjunction with the `git` command line tool. 55 | * Force push (i.e. `git push -f`) is totally normal and a required part of the 56 | PR workflow (despite what some guides will tell you). 57 | * You almost never need to close and create a new PR to resolve an issue with 58 | your PR / commits. If you think you need to close your PR to update it, please 59 | raise an issue against this repo to describe your scenario and I can help you. 60 | * Never use `git merge`. MicroPython maintains a completely linear history. 61 | * You almost never need to use `git pull`. The one exception is if you want to 62 | update the master branch with the latest changes. I prefer to work with 63 | "detached head" for this, i.e. `git fetch origin; git switch --detach origin/master`. 64 | * Consider adding [git aliases](https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases) 65 | to simplify common tasks. e.g. I have `git rmi` for `git rebase -i origin/master`. 66 | 67 | ## Assumptions 68 | 69 | This guide assumes you've already set up your fork and local clone, and have 70 | the "upstream" `micropython/micropython` repository as a remote named 71 | `origin`, and your fork as a second remote (e.g. named the same as your GitHub 72 | username). 73 | 74 | For example, I have: 75 | 76 | ```bash 77 | $ git remote -v 78 | jimmo git@github.com:jimmo/micropython.git (fetch) 79 | jimmo git@github.com:jimmo/micropython.git (push) 80 | origin git@github.com:micropython/micropython.git (fetch) 81 | origin git@github.com:micropython/micropython.git (push) 82 | ``` 83 | 84 | **These remotes can be named whatever you like**, but the rest of the guide 85 | will use `origin` to mean "the remote that is `micropython/micropython`, and 86 | `jimmo` to mean the remote that points to my fork. Substitute `jimmo` in this 87 | guide with your username. 88 | 89 | ### Other remote naming schemes 90 | 91 | It is also common to use `origin` as the remote pointing to your fork, and 92 | `upstream` to mean `micropython/micropython`. I discourage this because 93 | 94 | a) It feels "natural" that `origin/master` should be the latest upstream code. 95 | Your local `master` branch should track `origin/master`, and it's a hassle 96 | to keep your fork's `master` branch updated. 97 | b) "upstream" can be confused with the concept of a branch's "upstream branch" 98 | (i.e. the `--set-upstream` flag in `git push`). 99 | c) It is common for a contributor to first start as a MicroPython user, i.e. 100 | the first repo they clone will be `micropython/micropython`, hence that 101 | will be their `origin`, then later they create and add their fork as a 102 | remote. 103 | d) On every project I work with, `origin` is always the "source" (i.e. the 104 | main project). `origin/master` (or ideally, `origin/main`) is _always_ the 105 | latest code for the project. This is true regardless of whether it's one of 106 | my tiny repos or a big project (e.g. Zephyr or MicroPython). 107 | e) Sometimes you want to add other remotes (e.g. other contributors, or 108 | downstream forks, and this allows you to keep with the pattern of using the 109 | username, e.g. `adafruit`). 110 | 111 | But as above, you are welcome to set it up this way too. For example: 112 | 113 | ```bash 114 | $ git remote -v 115 | origin git@github.com:jimmo/micropython.git (fetch) 116 | origin git@github.com:jimmo/micropython.git (push) 117 | upstream git@github.com:micropython/micropython.git (fetch) 118 | upstream git@github.com:micropython/micropython.git (push) 119 | ``` 120 | 121 | And then you would use `git fetch upstream` anywhere I have written `git fetch 122 | origin` below, and `git push -u origin` where I have written `git push -u 123 | jimmo` below. 124 | 125 | ### Authentication 126 | 127 | Note these remotes all use `git@`, i.e. they rely on having set up [SSH key 128 | authentication to GitHub](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/about-ssh). You can also [set up a passkey](https://docs.github.com/en/authentication/authenticating-with-a-passkey/about-passkeys). 129 | 130 | ### Starting from scratch 131 | 132 | #### Fork 133 | 134 | This can be done from the GitHub web interface, by [clicking the fork button](https://github.com/micropython/micropython/fork). You should leave the "Copy the master branch only" checkbox checked. 135 | 136 | #### Clone & add remotes 137 | 138 | Now you can clone the MicroPython repository locally: 139 | 140 | ```bash 141 | cd src 142 | git clone git@github.com:micropython/micropython.git 143 | cd micropython 144 | git remote add jimmo git@github.com:jimmo/micropython.git 145 | git fetch jimmo 146 | ``` 147 | 148 | # Scenarios 149 | 150 | ### Creating a new PR 151 | 152 | The typical workflow is: 153 | 154 | 1. Get the latest code from upstream: 155 | 156 | ```bash 157 | git fetch origin 158 | ``` 159 | 160 | 2. Create a new branch to work on your feature / fix, based on the latest 161 | code, and switch to it: 162 | 163 | ``` 164 | git switch -c origin/master 165 | ``` 166 | 167 | 3. Implement your feature: 168 | 169 | Use `git add` and `git commit -s` to build up your set of commits. 170 | 171 | Use `git rebase -i origin/master` to restructure commits as necessary. 172 | 173 | 4. Create the PR: 174 | 175 | ``` 176 | git push -u jimmo 177 | ``` 178 | 179 | Change `jimmo` to the name of your fork's remote (your GitHub username if 180 | you're using the instructions above). The `-u` flag will make this the 181 | "upstream" for this branch, so that subsequent pushes will automatically go 182 | there. 183 | 184 | ### I need to fix a commit message 185 | 186 | The MicroPython CI will fail if the commit messages aren't formatted according 187 | to the [code conventions](https://github.com/micropython/micropython/blob/master/CODECONVENTIONS.md#git-commit-conventions). 188 | 189 | You can click on "Details" on the failing "Check commit message formatting" 190 | check and see the output from the verification tool. 191 | 192 | To fix the commit messages, you need to amend the commits and then force push 193 | the branch. The process to do this depends on whether you have multiple 194 | commits or just a single commit. 195 | 196 | #### My PR only has one commit 197 | 198 | Run 199 | 200 | ```bash 201 | git switch 202 | git commit --amend -s 203 | git push -f 204 | ``` 205 | 206 | This will amend the commit, and `-s` will automatically add the 207 | `Signed-Off-By` line if necessary. 208 | 209 | #### My PR has multiple commits 210 | 211 | This is done by using the "reword" feature of `git rebase`. 212 | 213 | ```bash 214 | git fetch origin 215 | git switch 216 | git rebase -i origin/master 217 | ``` 218 | 219 | Then for each commit you need to update, change `pick` to `reword` in the 220 | interactive TODO list. This will prompt you to edit the commit message for 221 | each of the selected commits. 222 | 223 | Finally force-push the branch with 224 | 225 | ```bash 226 | git push -f 227 | ``` 228 | 229 | to update the PR. 230 | 231 | ### I forgot to sign off a commit 232 | 233 | You can use the `-s` flag to `git commit` to add the `Signed-Off-By` line, but 234 | it's easy to forget, and so the automated checks will flag this if your 235 | commits are missing it. 236 | 237 | The way to fix this is similar as for the scenario above to update your commit 238 | messages. The `-s` flag to `git commit --amend` will add the `Signed-Off-By` 239 | line automatically if it's not already present. 240 | 241 | #### My PR only has one commit 242 | 243 | Run 244 | 245 | ```bash 246 | git switch 247 | git commit --amend -s 248 | git push -f 249 | ``` 250 | 251 | #### My PR has multiple commits 252 | 253 | The way to do this is essentially the same as for a single commit, except by 254 | using `git rebase` to do it for each commit in the branch. 255 | 256 | ```bash 257 | git fetch origin 258 | git switch 259 | git rebase -i origin/master 260 | ``` 261 | 262 | Then for each commit you need to update, change `pick` to `edit` in the interactive TODO 263 | list. Then you can run 264 | 265 | ```bash 266 | git commit --amend -s 267 | git rebase --continue 268 | ``` 269 | 270 | for each commit, and finally force-push the branch with 271 | 272 | ```bash 273 | git push -f 274 | ``` 275 | 276 | to update the PR. 277 | 278 | ### I need to rebase my PR / branch 279 | 280 | You will have created your branch at some point by branching off the `master` 281 | branch. But periodically you will want to rebase in order to get the latest 282 | changes. 283 | 284 | Run 285 | 286 | ```bash 287 | git fetch origin 288 | git switch 289 | git rebase -i origin/master 290 | git push -f 291 | ``` 292 | 293 | You don't strictly need the `-i` (interactive) on the rebase, but it's a good 294 | check that it's going to do what you expect (i.e. it should list just your 295 | commits). 296 | 297 | ### I want to make changes to the commits my PR / branch 298 | 299 | For example, to address review comments, or just to keep working on it after 300 | creating the PR. 301 | 302 | #### My PR only has one commit 303 | 304 | Make your changes, stage them (with `git add`) and then use `git commit --amend` 305 | to add them to the existing commit. Then `git push -f` to update the PR. You can 306 | also use `git commit --amend -a` to avoid needing to use `git add`. 307 | 308 | #### My PR has multiple commits 309 | 310 | It is common that you need to make changes that need to go into different 311 | commits. There are lots of ways to do this, but I find the simplest workflow 312 | is to make new (temporary) fixup commits with changes for each of your 313 | existing commits, and then "fix" them into those commits. 314 | 315 | _This is a workflow that Sublime Merge makes especially easy -- instead of 316 | using `git add -p` you can graphically chose the files/hunks/lines to add to 317 | the fixup commits._ 318 | 319 | For example, if your PR branch had the following three commits: 320 | 321 | ``` 322 | - py/x.c: Add support for X. 323 | - py/y.c: Add support for Y. 324 | - py/z.c: Use X and Y to implement Z. 325 | ``` 326 | 327 | and furthermore, all three commits made changes to `py/runtime.h`. 328 | 329 | And now you have unstaged changes (e.g. address review comments) to 330 | `py/runtime.h`, `py/x.c`, `py/y.c` and `py/z.c`. 331 | 332 | Now create a temporary commit with just the changes relevant to the first 333 | commit. 334 | 335 | ```bash 336 | git add -p py/runtime.h 337 | git add py/x.c 338 | git commit -m 'fixup! fixes for X.' 339 | ``` 340 | 341 | `git add -p` will let you selectively choose the changes to `py/runtime.h` 342 | that you want. 343 | 344 | Now same for the second and third commits: 345 | 346 | ```bash 347 | git add -p py/runtime.h 348 | git add py/y.c 349 | git commit -m 'fixup! fixes for Y.' 350 | git add -p py/runtime.h 351 | git add py/z.c 352 | git commit -m 'fixup! fixes for Z.' 353 | ``` 354 | 355 | Now "fix" them into the original commit (and rebase while you're at it) 356 | 357 | ```bash 358 | git fetch origin 359 | git rebase -i origin/master 360 | ``` 361 | 362 | Re-order the lines so that they are grouped, and change `pick` to `fix` for 363 | the fixup commits. 364 | 365 | ``` 366 | pick py/x.c: Add support for X. 367 | fix fixup! fixes for X. 368 | pick py/y.c: Add support for Y. 369 | fix fixup! fixes for Y. 370 | pick py/z.c: Use X and Y to implement Z. 371 | fix fixup! fixes for Z. 372 | ``` 373 | 374 | Then `git push -f` to update the PR. 375 | 376 | This also works for adding/removing/moving files. 377 | 378 | ### A maintainer made changes to my branch 379 | 380 | We generally only do this immediately before merging your PR. If you use 381 | `git pull` (and especially if you do not have `[pull] rebase = true` in your 382 | `.gitconfig`), it will likely get into a mess. 383 | 384 | Instead what you should do is fetch your fork's remote, then reset the branch to this: 385 | 386 | ``` 387 | git fetch jimmo 388 | git switch 389 | git reset --hard jimmo/ 390 | ``` 391 | 392 | This is essentially saying: "just make my local branch equal to the updated remote". 393 | 394 | ### I want to add IDE-specific rules to `.gitignore` 395 | 396 | There are lots of reasons to add rules to `.gitignore`, but we typically 397 | prefer that you set up local rules instead. 398 | 399 | You can do this by adding rules (using the same format as `.gitignore`) to `.git/info/exclude`. 400 | 401 | ### I need to split my PR into smaller commits 402 | 403 | One option here is to soft reset your branch, which has the effect of 404 | unstaging all your changes, then re-create the commits. See the next scenario 405 | for how to do this. 406 | 407 | But usually you want to split just a single commit without re-creating the 408 | commit. For example, if you had the following 409 | 410 | ``` 411 | - py/x.c: Add support for X. 412 | - py/z.c: Add Y and use Y and X to implement Z. 413 | - tests/basics/z.py: Add test for Z. 414 | ``` 415 | 416 | and wanted to split the second commit, first to implement Y, then to implement 417 | Z. 418 | 419 | ``` 420 | git fetch origin 421 | git rebase -i origin/master 422 | ``` 423 | 424 | There are two ways to do this: 425 | 426 | #### Repeat the commit 427 | 428 | In the rebase TODO list, duplicate the line for the commit you want to split, 429 | and change `pick` to `edit` for both. 430 | 431 | Now you can remove the things from the first commit you don't want to be 432 | there. Stage these changes and use `git commit --amend` to update the commit 433 | message. Then `git rebase --continue` to move to the second commit, which will 434 | add back just the removed changes. Use `git commit --amend` to update the 435 | commit message, then `git rebase --continue` to finish. 436 | 437 | In more detail, what happens here is when the rebase attempts to apply the 438 | second copy of the original commit, it does so on the partial set of changes 439 | that you made in the modified first commit. 440 | 441 | It's possible you may see a rebase/merge conflict on the second commit. This 442 | is expected if you want the intermediate state to be something other than 443 | either "no change" or the final change. 444 | 445 | _Using a tool like Sublime Merge makes removing the unwanted changes from the 446 | first commit easy, because you can interactively remove the diffs._ 447 | 448 | #### Edit the commit 449 | 450 | Instead of the duplicate-commit approach, you can just switch the commit to 451 | `edit`, then use TODO... (stage the removal, with the un-removal unstaged). 452 | Then `git commit --amend`, then `git commit -a` to add a second commit. 453 | 454 | ### My branch is a mess, I want to recreate the commits from scratch 455 | 456 | This might be the case if your PR shows the expected diff, but the commit tab 457 | shows lots of unexpected commits (or merge commits). 458 | 459 | Run the following commands on your branch: 460 | 461 | ```bash 462 | git fetch origin 463 | git reset --soft origin/master 464 | ``` 465 | 466 | This will 467 | * Ensure that the `origin` remote is up to date, so that `origin/master` 468 | reflects the current latest state. 469 | * Reset your branch such that it points to the same commit as `origin/master`, 470 | but (thanks to `--soft`) preserve your changes. All your changes will now be 471 | unstaged, ready to be staged (via `git add`) and committed. 472 | 473 | For example, you might now do the following to create a commit 474 | 475 | ```bash 476 | git add -p 477 | git commit -s 478 | ``` 479 | 480 | This will allow you to interactively chose which differences you want to use, 481 | and then commit them (with sign-off). Repeat this until you have no more 482 | unstaged changes. 483 | 484 | Then you can use 485 | 486 | ```bash 487 | git push -f 488 | ``` 489 | 490 | to update the PR. 491 | 492 | ### I want to test someone's PR 493 | 494 | If you know the PR number, you can make a local branch with the contents of 495 | that PR. 496 | 497 | ```bash 498 | git fetch origin pull//head:_ 499 | git switch _ 500 | ``` 501 | 502 | If you plan to make changes, you may want to create your own branch from this 503 | point. 504 | 505 | If they update the PR, you can use: 506 | 507 | ```bash 508 | git fetch -f origin pull//head:_ 509 | ``` 510 | 511 | to force update it from the remote. If you are currently on this branch, you 512 | must temporarily switch to another branch before doing this, e.g. 513 | 514 | ``` 515 | git switch --detach 516 | git fetch -f origin pull//head:_ 517 | git switch - 518 | ``` 519 | 520 | which will detach HEAD, fetch the branch, then switch back to the branch. 521 | 522 | _Note: You can use anything you like in place of `_` as 523 | the local branch name, this is just my convention._ 524 | 525 | # Concepts 526 | 527 | ## Remotes & forks 528 | 529 | TODO 530 | 531 | ## Rebasing 532 | 533 | TODO 534 | 535 | ## Sign off 536 | 537 | This is MicroPython's equivalent of a [Developer Certificate of Origin](https://en.wikipedia.org/wiki/Developer_Certificate_of_Origin). See also 538 | [The Developer Certificate of Origin is a great alternative to a CLA](https://drewdevault.com/2021/04/12/DCO.html). 539 | 540 | See the [MicroPython Code Conventions](https://github.com/micropython/micropython/blob/master/CODECONVENTIONS.md#git-commit-conventions) 541 | for more details and the background about why the MicroPython project requires 542 | this. 543 | 544 | It is not the same thing as "commit signing", i.e. anything about PGP keys or cryptography is not relevant to this. 545 | 546 | In most cases, if you always remember to use `git commit -s` you'll never need 547 | to worry about this. You can use `git commit --amend -s` to add the sign-off 548 | you a commit you just created. 549 | --------------------------------------------------------------------------------