1
My First Contribution to the Git Project
2
========================================
3
+:sectanchors:
4
5
+[[summary]]
6
== Summary
7
8
This is a tutorial demonstrating the end-to-end workflow of creating a change to
9
the Git tree, sending it for review, and making changes based on comments.
10
11
+[[prerequisites]]
12
=== Prerequisites
13
14
This tutorial assumes you're already fairly familiar with using Git to manage
15
source code. The Git workflow steps will largely remain unexplained.
16
17
+[[related-reading]]
18
=== Related Reading
19
20
This tutorial aims to summarize the following documents, but the reader may find
23
- `Documentation/SubmittingPatches`
24
- `Documentation/howto/new-command.txt`
25
26
+[[getting-started]]
27
== Getting Started
28
29
+[[cloning]]
30
=== Clone the Git Repository
31
32
Git is mirrored in a number of locations. Clone the repository from one of them;
37
$ git clone https://github.com/git/git git
38
----
39
40
+[[identify-problem]]
41
=== Identify Problem to Solve
42
43
////
51
(We've seen some other effort in this space with the implementation of popular
52
commands such as `sl`.)
53
54
+[[setup-workspace]]
55
=== Set Up Your Workspace
56
57
Let's start by making a development branch to work on our changes. Per
70
We'll make a number of commits here in order to demonstrate how to send a topic
71
with multiple patches up for review simultaneously.
72
73
+[[code-it-up]]
74
== Code It Up!
75
76
NOTE: A reference implementation can be found at
77
https://github.com/nasamuffin/git/tree/psuh.
78
79
+[[add-new-command]]
80
=== Adding a New Command
81
82
Lots of the subcommands are written as builtins, which means they are
205
sake of brevity. However, fully-fleshed example commit messages are available
206
on the reference implementation linked at the top of this document.
207
208
+[[implementation]]
209
=== Implementation
210
211
It's probably useful to do at least something besides printing out a string.
369
$ git commit -sm "psuh: display the top of origin/master"
370
----
371
372
+[[add-documentation]]
373
=== Adding Documentation
374
375
Awesome! You've got a fantastic new command that you're ready to share with the
457
458
Go ahead and commit your new documentation change.
459
460
+[[add-usage]]
461
=== Adding Usage Text
462
463
Try and run `./bin-wrappers/git psuh -h`. Your command should crash at the end.
514
515
Go ahead and commit this one, too.
516
517
+[[testing]]
518
== Testing
519
520
It's important to test your code - even for a little toy command like this one.
529
530
Related reading: `t/README`
531
532
+[[overview-test-structure]]
533
=== Overview of Testing Structure
534
535
The tests in Git live in `t/` and are named with a 4-digit decimal number using
536
the schema shown in the Naming Tests section of `t/README`.
537
538
+[[write-new-test]]
539
=== Writing Your Test
540
541
Since this a toy command, let's go ahead and name the test with t9999. However,
584
by running `make -C t test-lint`, which will check for things like test number
585
uniqueness, executable bit, and so on.
586
587
+[[local-test]]
588
=== Running Locally
589
590
Let's try and run locally:
608
609
Go ahead and commit this change, as well.
610
611
+[[ready-to-share]]
612
== Getting Ready to Share
613
614
You may have noticed already that the Git project performs its code reviews via
631
the same; the review process will be covered after the sections on GitGitGadget
632
and `git send-email`.
633
634
+[[howto-ggg]]
635
== Sending Patches via GitGitGadget
636
637
One option for sending patches is to follow a typical pull request workflow and
642
emails and send them out for you. It also runs the Git continuous integration
643
suite for you. It's documented at http://gitgitgadget.github.io.
644
645
+[[create-fork]]
646
=== Forking `git/git` on GitHub
647
648
Before you can send your patch off to be reviewed using GitGitGadget, you will
652
Head to the https://github.com/git/git[GitHub mirror] and look for the Fork
653
button. Place your fork wherever you deem appropriate and create it.
654
655
+[[upload-to-fork]]
656
=== Uploading to Your Own Fork
657
658
To upload your branch to your own fork, you'll need to add the new fork as a
698
699
Now you should be able to go and check out your newly created branch on GitHub.
700
701
+[[send-pr-ggg]]
702
=== Sending a PR to GitGitGadget
703
704
In order to have your code tested and formatted for review, you need to start by
710
Review the PR's title and description, as it's used by GitGitGadget as the cover
711
letter for your change. When you're happy, submit your pull request.
712
713
+[[run-ci-ggg]]
714
=== Running CI and Getting Ready to Send
715
716
If it's your first time using GitGitGadget (which is likely, as you're using
735
TODO https://github.com/gitgitgadget/gitgitgadget/issues/83
736
It'd be nice to be able to verify that the patch looks good before sending it
737
to everyone on Git mailing list.
738
+[[check-work-ggg]]
739
=== Check Your Work
740
////
741
742
+[[send-mail-ggg]]
743
=== Sending Your Patches
744
745
Now that your CI is passing and someone has granted you permission to use
746
GitGitGadget with the `/allow` command, sending out for review is as simple as
747
commenting on your PR with `/submit`.
748
749
+[[responding-ggg]]
750
=== Updating With Comments
751
752
Skip ahead to <<reviewing,Responding to Reviews>> for information on how to
768
more with `/submit` - GitGitGadget will automatically add a v2 mark to your
769
changes.
770
771
+[[howto-git-send-email]]
772
== Sending Patches with `git send-email`
773
774
If you don't want to use GitGitGadget, you can also use Git itself to mail your
777
and being able to send a ``dry run'' mail to yourself to ensure it all looks
778
good before going out to the list.
779
780
+[[setup-git-send-email]]
781
=== Prerequisite: Setting Up `git send-email`
782
783
Configuration for `send-email` can vary based on your operating system and email
789
configuration can change significantly based on your system and email setup, it
790
is out of scope for the context of this tutorial.
791
792
+[[format-patch]]
793
=== Preparing Initial Patchset
794
795
Sending emails with Git is a two-part process; before you can prepare the emails
828
Check and make sure that your patches and cover letter template exist in the
829
directory you specified - you're nearly ready to send out your review!
830
831
+[[cover-letter]]
832
=== Preparing Email
833
834
In addition to an email per patch, the Git community also expects your patches
892
Finally, the letter will include the version of Git used to generate the
893
patches. You can leave that string alone.
894
895
+[[sending-git-send-email]]
896
=== Sending Email
897
898
At this point you should have a directory `psuh/` which is filled with your
917
Awesome, now the community will drop everything and review your changes. (Just
918
kidding - be patient!)
919
920
+[[v2-git-send-email]]
921
=== Sending v2
922
923
Skip ahead to <<reviewing,Responding to Reviews>> for information on how to
976
psuh/v2*
977
----
978
979
+[[single-patch]]
980
=== Bonus Chapter: One-Patch Changes
981
982
In some cases, your very small change may consist of only one patch. When that
1024
2.21.0.392.gf8f6787159e-goog
1025
----
1026
1027
+[[now-what]]
1028
== My Patch Got Emailed - Now What?
1029
1030
[[reviewing]]
1068
anyone, that is okay for now! (Later, it may not make sense to do this; take a
1069
look at the section below this one for some context.)
1070
1071
+[[after-approval]]
1072
=== After Review Approval
1073
1074
The Git project has four integration branches: `pu`, `next`, `master`, and