11My First Contribution to the Git Project
22========================================
3+ :sectanchors:
34
5+ [[summary]]
46== Summary
57
68This is a tutorial demonstrating the end-to-end workflow of creating a change to
79the Git tree, sending it for review, and making changes based on comments.
810
11+ [[prerequisites]]
912=== Prerequisites
1013
1114This tutorial assumes you're already fairly familiar with using Git to manage
1215source code. The Git workflow steps will largely remain unexplained.
1316
17+ [[related-reading]]
1418=== Related Reading
1519
1620This tutorial aims to summarize the following documents, but the reader may find
@@ -19,8 +23,10 @@ useful additional context:
1923- `Documentation/SubmittingPatches`
2024- `Documentation/howto/new-command.txt`
2125
26+ [[getting-started]]
2227== Getting Started
2328
29+ [[cloning]]
2430=== Clone the Git Repository
2531
2632Git is mirrored in a number of locations. Clone the repository from one of them;
@@ -31,6 +37,7 @@ the official mirror on GitHub.
3137$ git clone https://github.com/git/git git
3238----
3339
40+ [[identify-problem]]
3441=== Identify Problem to Solve
3542
3643////
@@ -44,6 +51,7 @@ of invocation during users' typical daily workflow.
4451(We've seen some other effort in this space with the implementation of popular
4552commands such as `sl`.)
4653
54+ [[setup-workspace]]
4755=== Set Up Your Workspace
4856
4957Let's start by making a development branch to work on our changes. Per
@@ -62,11 +70,13 @@ $ git checkout -b psuh origin/master
6270We'll make a number of commits here in order to demonstrate how to send a topic
6371with multiple patches up for review simultaneously.
6472
73+ [[code-it-up]]
6574== Code It Up!
6675
6776NOTE: A reference implementation can be found at
6877https://github.com/nasamuffin/git/tree/psuh.
6978
79+ [[add-new-command]]
7080=== Adding a New Command
7181
7282Lots of the subcommands are written as builtins, which means they are
@@ -195,6 +205,7 @@ For the remainder of the tutorial, the subject line only will be listed for the
195205sake of brevity. However, fully-fleshed example commit messages are available
196206on the reference implementation linked at the top of this document.
197207
208+ [[implementation]]
198209=== Implementation
199210
200211It's probably useful to do at least something besides printing out a string.
@@ -359,6 +370,7 @@ about. Neat! Let's commit that as well.
359370$ git commit -sm "psuh: display the top of origin/master"
360371----
361372
373+ [[add-documentation]]
362374=== Adding Documentation
363375
364376Awesome! You've got a fantastic new command that you're ready to share with the
@@ -446,6 +458,7 @@ sees that your command has been implemented as well as documented) by running
446458
447459Go ahead and commit your new documentation change.
448460
461+ [[add-usage]]
449462=== Adding Usage Text
450463
451464Try and run `./bin-wrappers/git psuh -h`. Your command should crash at the end.
@@ -502,6 +515,7 @@ your command terminated before anything else interesting happens. Great!
502515
503516Go ahead and commit this one, too.
504517
518+ [[testing]]
505519== Testing
506520
507521It's important to test your code - even for a little toy command like this one.
@@ -516,11 +530,13 @@ So let's write some tests.
516530
517531Related reading: `t/README`
518532
533+ [[overview-test-structure]]
519534=== Overview of Testing Structure
520535
521536The tests in Git live in `t/` and are named with a 4-digit decimal number using
522537the schema shown in the Naming Tests section of `t/README`.
523538
539+ [[write-new-test]]
524540=== Writing Your Test
525541
526542Since this a toy command, let's go ahead and name the test with t9999. However,
@@ -569,6 +585,7 @@ You can get an idea of whether you created your new test script successfully
569585by running `make -C t test-lint`, which will check for things like test number
570586uniqueness, executable bit, and so on.
571587
588+ [[local-test]]
572589=== Running Locally
573590
574591Let's try and run locally:
@@ -592,6 +609,7 @@ dependencies. `prove` also makes the output nicer.
592609
593610Go ahead and commit this change, as well.
594611
612+ [[ready-to-share]]
595613== Getting Ready to Share
596614
597615You may have noticed already that the Git project performs its code reviews via
@@ -614,6 +632,7 @@ Regardless of which method you choose, your engagement with reviewers will be
614632the same; the review process will be covered after the sections on GitGitGadget
615633and `git send-email`.
616634
635+ [[howto-ggg]]
617636== Sending Patches via GitGitGadget
618637
619638One option for sending patches is to follow a typical pull request workflow and
@@ -624,6 +643,7 @@ mirror of the Git project, and does some magic to turn the PR into a set of
624643emails and send them out for you. It also runs the Git continuous integration
625644suite for you. It's documented at http://gitgitgadget.github.io.
626645
646+ [[create-fork]]
627647=== Forking `git/git` on GitHub
628648
629649Before you can send your patch off to be reviewed using GitGitGadget, you will
@@ -633,6 +653,7 @@ you have a GitHub account.
633653Head to the https://github.com/git/git[GitHub mirror] and look for the Fork
634654button. Place your fork wherever you deem appropriate and create it.
635655
656+ [[upload-to-fork]]
636657=== Uploading to Your Own Fork
637658
638659To upload your branch to your own fork, you'll need to add the new fork as a
@@ -678,6 +699,7 @@ $ git push remotename psuh
678699
679700Now you should be able to go and check out your newly created branch on GitHub.
680701
702+ [[send-pr-ggg]]
681703=== Sending a PR to GitGitGadget
682704
683705In order to have your code tested and formatted for review, you need to start by
@@ -689,6 +711,7 @@ appear with the name of your newly pushed branch.
689711Review the PR's title and description, as it's used by GitGitGadget as the cover
690712letter for your change. When you're happy, submit your pull request.
691713
714+ [[run-ci-ggg]]
692715=== Running CI and Getting Ready to Send
693716
694717If it's your first time using GitGitGadget (which is likely, as you're using
@@ -713,15 +736,18 @@ your patch is accepted into `next`.
713736TODO https://github.com/gitgitgadget/gitgitgadget/issues/83
714737It'd be nice to be able to verify that the patch looks good before sending it
715738to everyone on Git mailing list.
739+ [[check-work-ggg]]
716740=== Check Your Work
717741////
718742
743+ [[send-mail-ggg]]
719744=== Sending Your Patches
720745
721746Now that your CI is passing and someone has granted you permission to use
722747GitGitGadget with the `/allow` command, sending out for review is as simple as
723748commenting on your PR with `/submit`.
724749
750+ [[responding-ggg]]
725751=== Updating With Comments
726752
727753Skip ahead to <<reviewing,Responding to Reviews>> for information on how to
@@ -743,6 +769,7 @@ of what they're looking at. When the CI is done running, you can comment once
743769more with `/submit` - GitGitGadget will automatically add a v2 mark to your
744770changes.
745771
772+ [[howto-git-send-email]]
746773== Sending Patches with `git send-email`
747774
748775If you don't want to use GitGitGadget, you can also use Git itself to mail your
@@ -751,6 +778,7 @@ subject line (for example, being able to use the tag [RFC PATCH] in the subject)
751778and being able to send a ``dry run'' mail to yourself to ensure it all looks
752779good before going out to the list.
753780
781+ [[setup-git-send-email]]
754782=== Prerequisite: Setting Up `git send-email`
755783
756784Configuration for `send-email` can vary based on your operating system and email
@@ -762,6 +790,7 @@ determine the right way to configure it to use your SMTP server; again, as this
762790configuration can change significantly based on your system and email setup, it
763791is out of scope for the context of this tutorial.
764792
793+ [[format-patch]]
765794=== Preparing Initial Patchset
766795
767796Sending emails with Git is a two-part process; before you can prepare the emails
@@ -800,6 +829,7 @@ but want reviewers to look at what they have so far. You can add this flag with
800829Check and make sure that your patches and cover letter template exist in the
801830directory you specified - you're nearly ready to send out your review!
802831
832+ [[cover-letter]]
803833=== Preparing Email
804834
805835In addition to an email per patch, the Git community also expects your patches
@@ -863,6 +893,7 @@ The one generated for `psuh` from the sample implementation looks like this:
863893Finally, the letter will include the version of Git used to generate the
864894patches. You can leave that string alone.
865895
896+ [[sending-git-send-email]]
866897=== Sending Email
867898
868899At this point you should have a directory `psuh/` which is filled with your
@@ -887,6 +918,7 @@ press `y` or `a` at these prompts your emails will be sent! Congratulations!
887918Awesome, now the community will drop everything and review your changes. (Just
888919kidding - be patient!)
889920
921+ [[v2-git-send-email]]
890922=== Sending v2
891923
892924Skip ahead to <<reviewing,Responding to Reviews>> for information on how to
@@ -945,6 +977,7 @@ $ git send-email --to=target@example.com
945977 psuh/v2*
946978----
947979
980+ [[single-patch]]
948981=== Bonus Chapter: One-Patch Changes
949982
950983In some cases, your very small change may consist of only one patch. When that
@@ -992,6 +1025,7 @@ index 88f126184c..38da593a60 100644
99210252.21.0.392.gf8f6787159e-goog
9931026----
9941027
1028+ [[now-what]]
9951029== My Patch Got Emailed - Now What?
9961030
9971031[[reviewing]]
@@ -1035,6 +1069,7 @@ changing history, but since it's local history which you haven't shared with
10351069anyone, that is okay for now! (Later, it may not make sense to do this; take a
10361070look at the section below this one for some context.)
10371071
1072+ [[after-approval]]
10381073=== After Review Approval
10391074
10401075The Git project has four integration branches: `pu`, `next`, `master`, and
0 commit comments