1
1
My First Contribution to the Git Project
2
2
========================================
3
+ :sectanchors:
3
4
5
+ [[summary]]
4
6
== Summary
5
7
6
8
This is a tutorial demonstrating the end-to-end workflow of creating a change to
7
9
the Git tree, sending it for review, and making changes based on comments.
8
10
11
+ [[prerequisites]]
9
12
=== Prerequisites
10
13
11
14
This tutorial assumes you're already fairly familiar with using Git to manage
12
15
source code. The Git workflow steps will largely remain unexplained.
13
16
17
+ [[related-reading]]
14
18
=== Related Reading
15
19
16
20
This tutorial aims to summarize the following documents, but the reader may find
@@ -19,8 +23,10 @@ useful additional context:
19
23
- `Documentation/SubmittingPatches`
20
24
- `Documentation/howto/new-command.txt`
21
25
26
+ [[getting-started]]
22
27
== Getting Started
23
28
29
+ [[cloning]]
24
30
=== Clone the Git Repository
25
31
26
32
Git is mirrored in a number of locations. Clone the repository from one of them;
@@ -31,6 +37,7 @@ the mirror on GitHub.
31
37
$ git clone https://github.com/git/git git
32
38
----
33
39
40
+ [[identify-problem]]
34
41
=== Identify Problem to Solve
35
42
36
43
////
@@ -44,6 +51,7 @@ of invocation during users' typical daily workflow.
44
51
(We've seen some other effort in this space with the implementation of popular
45
52
commands such as `sl`.)
46
53
54
+ [[setup-workspace]]
47
55
=== Set Up Your Workspace
48
56
49
57
Let's start by making a development branch to work on our changes. Per
@@ -62,11 +70,13 @@ $ git checkout -b psuh origin/master
62
70
We'll make a number of commits here in order to demonstrate how to send a topic
63
71
with multiple patches up for review simultaneously.
64
72
73
+ [[code-it-up]]
65
74
== Code It Up!
66
75
67
76
NOTE: A reference implementation can be found at
68
77
https://github.com/nasamuffin/git/tree/psuh.
69
78
79
+ [[add-new-command]]
70
80
=== Adding a New Command
71
81
72
82
Lots 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
195
205
sake of brevity. However, fully-fleshed example commit messages are available
196
206
on the reference implementation linked at the top of this document.
197
207
208
+ [[implementation]]
198
209
=== Implementation
199
210
200
211
It's probably useful to do at least something besides printing out a string.
@@ -358,6 +369,7 @@ about. Neat! Let's commit that as well.
358
369
$ git commit -sm "psuh: display the top of origin/master"
359
370
----
360
371
372
+ [[add-documentation]]
361
373
=== Adding Documentation
362
374
363
375
Awesome! You've got a fantastic new command that you're ready to share with the
@@ -445,6 +457,7 @@ sees that your command has been implemented as well as documented) by running
445
457
446
458
Go ahead and commit your new documentation change.
447
459
460
+ [[add-usage]]
448
461
=== Adding Usage Text
449
462
450
463
Try and run `./bin-wrappers/git psuh -h`. Your command should crash at the end.
@@ -501,6 +514,7 @@ your command terminated before anything else interesting happens. Great!
501
514
502
515
Go ahead and commit this one, too.
503
516
517
+ [[testing]]
504
518
== Testing
505
519
506
520
It's important to test your code - even for a little toy command like this one.
@@ -515,11 +529,13 @@ So let's write some tests.
515
529
516
530
Related reading: `t/README`
517
531
532
+ [[overview-test-structure]]
518
533
=== Overview of Testing Structure
519
534
520
535
The tests in Git live in `t/` and are named with a 4-digit decimal number using
521
536
the schema shown in the Naming Tests section of `t/README`.
522
537
538
+ [[write-new-test]]
523
539
=== Writing Your Test
524
540
525
541
Since this a toy command, let's go ahead and name the test with t9999. However,
@@ -568,6 +584,7 @@ You can get an idea of whether you created your new test script successfully
568
584
by running `make -C t test-lint`, which will check for things like test number
569
585
uniqueness, executable bit, and so on.
570
586
587
+ [[local-test]]
571
588
=== Running Locally
572
589
573
590
Let's try and run locally:
@@ -591,6 +608,7 @@ dependencies. `prove` also makes the output nicer.
591
608
592
609
Go ahead and commit this change, as well.
593
610
611
+ [[ready-to-share]]
594
612
== Getting Ready to Share
595
613
596
614
You may have noticed already that the Git project performs its code reviews via
@@ -613,6 +631,7 @@ Regardless of which method you choose, your engagement with reviewers will be
613
631
the same; the review process will be covered after the sections on GitGitGadget
614
632
and `git send-email`.
615
633
634
+ [[howto-ggg]]
616
635
== Sending Patches via GitGitGadget
617
636
618
637
One option for sending patches is to follow a typical pull request workflow and
@@ -623,6 +642,7 @@ mirror of the Git project, and does some magic to turn the PR into a set of
623
642
emails and send them out for you. It also runs the Git continuous integration
624
643
suite for you. It's documented at http://gitgitgadget.github.io.
625
644
645
+ [[create-fork]]
626
646
=== Forking `git/git` on GitHub
627
647
628
648
Before you can send your patch off to be reviewed using GitGitGadget, you will
@@ -632,6 +652,7 @@ you have a GitHub account.
632
652
Head to the https://github.com/git/git[GitHub mirror] and look for the Fork
633
653
button. Place your fork wherever you deem appropriate and create it.
634
654
655
+ [[upload-to-fork]]
635
656
=== Uploading to Your Own Fork
636
657
637
658
To upload your branch to your own fork, you'll need to add the new fork as a
@@ -677,6 +698,7 @@ $ git push remotename psuh
677
698
678
699
Now you should be able to go and check out your newly created branch on GitHub.
679
700
701
+ [[send-pr-ggg]]
680
702
=== Sending a PR to GitGitGadget
681
703
682
704
In order to have your code tested and formatted for review, you need to start by
@@ -688,6 +710,7 @@ appear with the name of your newly pushed branch.
688
710
Review the PR's title and description, as it's used by GitGitGadget as the cover
689
711
letter for your change. When you're happy, submit your pull request.
690
712
713
+ [[run-ci-ggg]]
691
714
=== Running CI and Getting Ready to Send
692
715
693
716
If it's your first time using GitGitGadget (which is likely, as you're using
@@ -712,15 +735,18 @@ your patch is accepted into `next`.
712
735
TODO https://github.com/gitgitgadget/gitgitgadget/issues/83
713
736
It'd be nice to be able to verify that the patch looks good before sending it
714
737
to everyone on Git mailing list.
738
+ [[check-work-ggg]]
715
739
=== Check Your Work
716
740
////
717
741
742
+ [[send-mail-ggg]]
718
743
=== Sending Your Patches
719
744
720
745
Now that your CI is passing and someone has granted you permission to use
721
746
GitGitGadget with the `/allow` command, sending out for review is as simple as
722
747
commenting on your PR with `/submit`.
723
748
749
+ [[responding-ggg]]
724
750
=== Updating With Comments
725
751
726
752
Skip ahead to <<reviewing,Responding to Reviews>> for information on how to
@@ -742,6 +768,7 @@ of what they're looking at. When the CI is done running, you can comment once
742
768
more with `/submit` - GitGitGadget will automatically add a v2 mark to your
743
769
changes.
744
770
771
+ [[howto-git-send-email]]
745
772
== Sending Patches with `git send-email`
746
773
747
774
If you don't want to use GitGitGadget, you can also use Git itself to mail your
@@ -750,6 +777,7 @@ subject line (for example, being able to use the tag [RFC PATCH] in the subject)
750
777
and being able to send a ``dry run'' mail to yourself to ensure it all looks
751
778
good before going out to the list.
752
779
780
+ [[setup-git-send-email]]
753
781
=== Prerequisite: Setting Up `git send-email`
754
782
755
783
Configuration for `send-email` can vary based on your operating system and email
@@ -761,6 +789,7 @@ determine the right way to configure it to use your SMTP server; again, as this
761
789
configuration can change significantly based on your system and email setup, it
762
790
is out of scope for the context of this tutorial.
763
791
792
+ [[format-patch]]
764
793
=== Preparing Initial Patchset
765
794
766
795
Sending emails with Git is a two-part process; before you can prepare the emails
@@ -799,6 +828,7 @@ but want reviewers to look at what they have so far. You can add this flag with
799
828
Check and make sure that your patches and cover letter template exist in the
800
829
directory you specified - you're nearly ready to send out your review!
801
830
831
+ [[cover-letter]]
802
832
=== Preparing Email
803
833
804
834
In addition to an email per patch, the Git community also expects your patches
@@ -862,6 +892,7 @@ The one generated for `psuh` from the sample implementation looks like this:
862
892
Finally, the letter will include the version of Git used to generate the
863
893
patches. You can leave that string alone.
864
894
895
+ [[sending-git-send-email]]
865
896
=== Sending Email
866
897
867
898
At this point you should have a directory `psuh/` which is filled with your
@@ -886,6 +917,7 @@ press `y` or `a` at these prompts your emails will be sent! Congratulations!
886
917
Awesome, now the community will drop everything and review your changes. (Just
887
918
kidding - be patient!)
888
919
920
+ [[v2-git-send-email]]
889
921
=== Sending v2
890
922
891
923
Skip ahead to <<reviewing,Responding to Reviews>> for information on how to
944
976
psuh/v2*
945
977
----
946
978
979
+ [[single-patch]]
947
980
=== Bonus Chapter: One-Patch Changes
948
981
949
982
In some cases, your very small change may consist of only one patch. When that
@@ -991,6 +1024,7 @@ index 88f126184c..38da593a60 100644
991
1024
2.21.0.392.gf8f6787159e-goog
992
1025
----
993
1026
1027
+ [[now-what]]
994
1028
== My Patch Got Emailed - Now What?
995
1029
996
1030
[[reviewing]]
@@ -1034,6 +1068,7 @@ changing history, but since it's local history which you haven't shared with
1034
1068
anyone, that is okay for now! (Later, it may not make sense to do this; take a
1035
1069
look at the section below this one for some context.)
1036
1070
1071
+ [[after-approval]]
1037
1072
=== After Review Approval
1038
1073
1039
1074
The Git project has four integration branches: `pu`, `next`, `master`, and
0 commit comments