1 @c -*- coding: utf-8; mode: texinfo; -*-
4 @node Working with source code
5 @chapter Working with source code
11 * Basic Git procedures::
12 * Advanced Git procedures::
14 * Repository directory structure::
15 * Other Git documentation::
20 @section Using lily-git
23 FIXME: Add instructions for using @command{lily-git} here.
26 @node Starting with Git
27 @section Starting with Git
30 Using the Git program directly (as opposed to using the
31 @command{lily-git} GUI) allows you to have much greater control
32 over the contributing process. You should consider using Git if
33 you want to work on complex projects, or if you want to work on
34 multiple projects concurrently.
39 * Downloading remote branches::
44 @subsection Setting up
47 FIXME: Remove this note if incorporating Windows instructions
48 throughout this section:
50 @warning{These instructions assume that you are using the
51 command-line version of Git 1.5 or higher. Windows users should
52 skip to @ref{Git on Windows}.}
56 * Initializing a repository::
62 @unnumberedsubsubsec Installing Git
65 If you are using a Unix-based machine, the easiest way to download
66 and install Git is through a package manager such as @command{rpm}
67 or @command{apt-get}---the installation is generally automatic.
68 The only required package is (usually) called @command{git-core},
69 although some of the auxiliary @command{git@var{*}} packages are
70 also useful (such as @command{gitk}).
72 Alternatively, you can visit the Git website
73 (@uref{http://git-scm.com/}) for downloadable binaries and
76 FIXME: add Windows installation instructions (or @@ref@{Git on
80 @node Initializing a repository
81 @unnumberedsubsubsec Initializing a repository
84 Once Git is installed, you'll need to create a new directory where
85 your initial repository will be stored (the example below uses
86 @file{~/lilypond-git/}, where @code{~} represents your home
87 directory). Run @command{git@tie{}init} from within the new
88 directory to initialize an empty repository:
91 mkdir ~/lilypond-git/; cd ~/lilypond-git/
95 @subsubheading Technical details
97 This creates (within the @file{~/lilypond-git/} directory) a
98 subdirectory called @file{.git/}, which Git uses to keep track of
99 changes to the repository, among other things. Normally you don't
100 need to access it, but it's good to know it's there.
103 @node Configuring Git
104 @unnumberedsubsubsec Configuring Git
106 @warning{Throughout the rest of this manual, all command-line
107 input should be entered from the top directory of the Git
108 repository being discussed (eg. @file{~/lilypond-git/}). This is
109 referred to as a @emph{top source directory}.}
111 Before downloading a copy of the main LilyPond repository, you
112 should configure some basic settings with the
113 @command{git@tie{}config} command. Git allows you to set both
114 global and repository-specific options.
116 To configure settings that affect all repositories, use the
117 @command{--global} command line option. For example, the first
118 two options that you should always set are your @var{name} and
119 @var{email}, since Git needs these to keep track of commit
123 git config --global user.name "@var{John Smith}"
124 git config --global user.email @var{john@@example.com}
127 To configure Git to use colored output where possible, use:
130 git config --global color.ui auto
133 The text editor that opens when using @command{git@tie{}commit}
134 can also be changed. If none of your editor-related environment
135 variables are set ($GIT_EDITOR, $VISUAL, or $EDITOR), the default
136 editor is usually @command{vi} or @command{vim}. If you're not
137 familiar with either of these, you should probably change the
138 default to an editor that you know how to use. For example, to
139 change the default editor to @command{nano}, enter:
142 git config --global core.editor @var{nano}
145 FIXME: Add instructions for changing the editor on Windows, which
146 is a little different, I think. -mp
148 @subsubheading Technical details
150 Git stores the information entered with
151 @command{git@tie{}config@tie{}--global} in the file
152 @file{.gitconfig}, located in your home directory. This file can
153 also be modified directly, without using
154 @command{git@tie{}config}. The @file{.gitconfig} file generated
155 by the above commands would look like this:
160 email = john@@example.com
167 Using the @command{git@tie{}config} command @emph{without} the
168 @command{--global} option configures repository-specific settings,
169 which are stored in the file @file{.git/config}. This file is
170 created when a repository is initialized (using
171 @command{git@tie{}init}), and by default contains these lines:
175 repositoryformatversion = 0
178 logallrefupdates = true
181 However, since different repository-specific options are
182 recommended for different development tasks, it is best to avoid
183 setting any now. Specific recommendations will be mentioned later
187 @node Downloading remote branches
188 @subsection Downloading remote branches
192 * Organization of remote branches::
193 * LilyPond repository sources::
194 * Downloading individual branches::
195 * Downloading all remote branches::
200 @node Organization of remote branches
201 @unnumberedsubsubsec Organization of remote branches
204 The main LilyPond repository is organized into @emph{branches} to
205 facilitate development. These are often called @emph{remote}
206 branches to distinguish them from @emph{local} branches you might
207 create yourself (see @ref{Using local branches}).
209 The @code{master} branch contains all the source files used to
210 build LilyPond, which includes the program itself (both stable and
211 development releases), the documentation (and its translations),
212 and the website. Generally, the @code{master} branch is expected
213 to compile successfully.
215 The @code{lilypond/translation} branch is a side branch that
216 allows translators to work without needing to worry about
217 compilation problems. Periodically, the Translation Meister
218 (after verifying that it doesn't break compilation), will
219 @emph{merge} this branch back into @code{master} to incorporate
220 recent translations. Similarly, the @code{master} branch is
221 usually merged into the @code{lilypond/translation} branch after
222 significant changes to the English documentation. See
223 @ref{Translating the documentation} for details.
226 @node LilyPond repository sources
227 @unnumberedsubsubsec LilyPond repository sources
230 The recommended source for downloading a copy of the main
234 git://git.sv.gnu.org/lilypond.git
237 However, if your internet router filters out connections using the
238 GIT protocol, or if you experience difficulty connecting via GIT,
239 you can try these other sources:
242 ssh://git.sv.gnu.org/srv/git/lilypond.git
243 http://git.sv.gnu.org/r/lilypond.git
246 The SSH protocol can only be used if your system is properly set
247 up to use it. Also, the HTTP protocol is slowest, so it should
248 only be used as a last resort.
251 @node Downloading individual branches
252 @unnumberedsubsubsec Downloading individual branches
255 Once you have initialized an empty Git repository on your system
256 (see @ref{Initializing a repository}), you can download a remote
257 branch into it. Make sure you know which branch you want to start
260 To download the @code{master} branch, enter the following:
263 git remote add -ft master -m master \
264 origin git://git.sv.gnu.org/lilypond.git/
267 To download the @code{lilypond/translation} branch, enter:
270 git remote add -ft lilypond/translation -m \
271 lilypond/translation origin git://git.sv.gnu.org/lilypond.git/
274 The @command{git@tie{}remote@tie{}add} process could take up to
275 ten minutes, depending on the speed of your connection. The
276 output will be something like this:
280 remote: Counting objects: 235967, done.
281 remote: Compressing objects: 100% (42721/42721), done.
282 remote: Total 235967 (delta 195098), reused 233311 (delta 192772)
283 Receiving objects: 100% (235967/235967), 68.37 MiB | 479 KiB/s, done.
284 Resolving deltas: 100% (195098/195098), done.
285 From git://git.sv.gnu.org/lilypond
286 * [new branch] master -> origin/master
287 From git://git.sv.gnu.org/lilypond
288 * [new tag] flower/1.0.1 -> flower/1.0.1
289 * [new tag] flower/1.0.10 -> flower/1.0.10
291 * [new tag] release/2.9.6 -> release/2.9.6
292 * [new tag] release/2.9.7 -> release/2.9.7
295 When @command{git@tie{}remote@tie{}add} is finished, the remote
296 branch should be downloaded into your repository---though not yet
297 in a form that you can use. In order to browse the source code
298 files, you need to @emph{create} and @emph{checkout} your own
299 local branch. In this case, however, it is easier to have Git
300 create the branch automatically by using the @command{checkout}
301 command on a non-existent branch. Enter the following:
304 git checkout -b @var{branch} origin/@var{branch}
308 where @code{@var{branch}} is the name of your tracking branch,
309 either @code{master} or @code{lilypond/translation}.
311 Git will issue some warnings; this is normal:
314 warning: You appear to be on a branch yet to be born.
315 warning: Forcing checkout of origin/master.
316 Branch master set up to track remote branch master from origin.
320 By now the source files should be accessible---you should be able
321 to edit any files in the @file{lilypond-git/} directory using a
322 text editor of your choice. But don't start just yet! Before
323 editing any source files, learn how to keep your changes organized
324 and prevent problems later---read @ref{Basic Git procedures}.
326 @subsubheading Technical Details
328 The @command{git@tie{}remote@tie{}add} command should add some
329 lines to your local repository's @file{.git/config} file:
333 url = git://git.sv.gnu.org/lilypond.git/
334 fetch = +refs/heads/master:refs/remotes/origin/master
338 @node Downloading all remote branches
339 @unnumberedsubsubsec Downloading all remote branches
342 To download all remote branches at once, you can @command{clone}
343 the entire repository:
346 git clone git://git.sv.gnu.org/lilypond.git
351 @unnumberedsubsubsec Other branches
353 Most contributors will never need to touch the other branches. If
354 you wish to do so, you will need more familiarity with Git; please
355 see @ref{Other Git documentation}.
358 @item @code{dev/XYZ}:
359 These branches are for individual developers. They store code
360 which is not yet stable enough to be added to the @code{master}
363 @item @code{stable/XYZ}:
364 The branches are kept for archival reasons.
368 Another item of interest might be the Grand Unified Builder, our
369 cross-platform building tool. Since it is used by projects as
370 well, it is not stored in our gub repository. For more info, see
371 @uref{http://lilypond.org/gub}. The git location is
372 @uref{http://github.com/janneke/gub}.
375 @node Basic Git procedures
376 @section Basic Git procedures
380 * The Git contributor's cycle::
381 * Pulling and rebasing::
382 * Using local branches::
383 * Commits and patches::
387 @node The Git contributor's cycle
388 @subsection The Git contributor's cycle
391 Here is a simplified view of the contribution process on Git:
395 Update your local repository by @emph{pulling} the most recent
396 updates from the remote repository.
399 Edit source files within your local repository's @emph{working
403 @emph{Commit} the changes you've made to a local @emph{branch}.
406 Generate a @emph{patch} to share your changes with the developers.
410 @node Pulling and rebasing
411 @subsection Pulling and rebasing
414 When developers push new patches to the @code{git.sv.gnu.org}
415 repository, your local repository is @strong{not} automatically
416 updated. It is important to keep your repository up-to-date by
417 periodically @emph{pulling} the most recent @emph{commits} from
418 the remote branch. Developers expect patches to be as current as
419 possible, since outdated patches require extra work before they
422 Occasionally you may need to rework some of your own modifications
423 to match changes made to the remote branch (see @ref{Resolving
424 conflicts}), and it's considerably easier to rework things
425 incrementally. If you don't update your repository along the way,
426 you may have to spend a lot of time resolving branch conflicts and
427 reconfiguring much of the work you've already done.
429 Fortunately, Git is able to resolve certain types of branch
430 conflicts automatically with a process called @emph{rebasing}.
431 When rebasing, Git tries to modify your old commits so they appear
432 as new commits (based on the latest updates). For a more involved
433 explanation, see the @command{git-rebase} man page.
435 To pull without rebasing (recommended for translators), use the
439 git pull # recommended for translators
442 If you're tracking the remote @code{master} branch, you should add
443 the @code{-r} option (short for @code{--rebase}) to keep commits
444 on your local branch current:
447 git pull -r # use with caution when translating
450 If you don't edit translated documentation and don't want to type
451 @code{-r} every time, configure the master branch to rebase by
452 default with this command:
455 git config branch.master.rebase true
458 FIXME: I think the next paragraph is confusing. Perhaps prepare
459 the reader for new terms `committish' and `head'? -mp
461 @warning{translators and documentation editors, if you have
462 changed committishes in the head of translated files using commits
463 you have not yet pushed to @code{git.sv.gnu.org}, please do not
464 rebase. If you want to avoid wondering whether you should rebase
465 each time you pull, please always use committishes from master
466 and/or lilypond/translation branch on @code{git.sv.gnu.org}, which
467 in particular implies that you must push your changes to
468 documentation except committishes updates (possibly after having
469 rebased), then update the committishes and push them.}
471 FIXME: when committishes automatic conditional update have been
472 tested and documented, append the following to the warning above:
473 Note that using update-committishes make target generally touches
476 @subsubheading Technical details
478 The @command{git@tie{}config} command mentioned above adds the
479 line @code{rebase = true} to the master branch in your local
480 repository's @file{.git/config} file:
485 merge = refs/heads/master
490 @node Using local branches
491 @subsection Using local branches
495 * Creating and removing branches::
496 * Listing branches and remotes::
497 * Checking out branches::
502 @node Creating and removing branches
503 @unnumberedsubsubsec Creating and removing branches
506 Local branches are useful when you're working on several different
507 projects concurrently. To create a new branch, enter:
510 git branch @var{name}
513 To delete a branch, enter:
516 git branch -d @var{name}
519 Git will ask you for confirmation if it sees that data would be
520 lost by deleting the branch. Use @code{-D} instead of @code{-d}
521 to bypass this. Note that you cannot delete a branch if it is
522 currently checked out.
525 @node Listing branches and remotes
526 @unnumberedsubsubsec Listing branches and remotes
528 You can get the exact path or URL of all remote branches by
535 To list Git branches on your local repositories, run
538 git branch # list local branches only
539 git branch -r # list remote branches
540 git branch -a # list all branches
544 @node Checking out branches
545 @unnumberedsubsubsec Checking out branches
547 To know the currently checked out branch, i.e. the branch whose
548 source files are present in your working tree, read the first line
556 The currently checked out branch is also marked with an asterisk
557 in the output of @command{git branch}.
559 You can check out another branch @code{@var{other_branch}}, i.e.
560 check out @code{@var{other_branch}} to the working tree, by
564 git checkout @var{other_branch}
567 Note that it is possible to check out another branch while having
568 uncommitted changes, but it is not recommended unless you know
569 what you are doing; it is recommended to run @command{git status}
570 to check this kind of issue before checking out another branch.
572 @node Merging branches
573 @unnumberedsubsubsec Merging branches
575 To merge branch @code{@var{foo}} into branch @code{@var{bar}},
576 i.e. to @qq{add} all changes made in branch @code{@var{foo}} to
577 branch @code{@var{bar}}, run
580 git checkout @var{bar}
584 If any conflict happens, see @ref{Resolving conflicts}.
586 There are common usage cases for merging: as a translator, you
587 will often want to merge @code{master} into
588 @code{lilypond/translation}; on the other hand, the Translations
589 meister wants to merge @code{lilypond/translation} into
590 @code{master} whenever he has checked that
591 @code{lilypond/translation} builds successfully.
594 @node Commits and patches
595 @subsection Commits and patches
599 * Understanding commits::
606 @node Understanding commits
607 @unnumberedsubsubsec Understanding commits
609 Technically, a @emph{commit} is a single point in the history of a
610 branch, but most developers use the term to mean a @emph{commit
611 object}, which stores information about a particular revision. A
612 single commit can record changes to multiple source files, and
613 typically represents one logical set of related changes (such as a
614 bug-fix). You can list the ten most recent commits in your
615 current branch with this command:
618 git log -10 --oneline
621 If you're using an older version of Git and get an @q{unrecognized
622 argument} error, use this instead:
625 git log -10 --pretty=oneline --abbrev-commit
628 More interactive lists of the commits on the remote @code{master}
629 branch are available at
630 @uref{http://git.sv.gnu.org/gitweb/?p=lilypond.git;a=shortlog} and
631 @uref{http://git.sv.gnu.org/cgit/lilypond.git/log/}.
635 @unnumberedsubsubsec Making commits
638 Once you have modified some source files in your working
639 directory, you can make a commit with the following procedure:
643 Make sure you've configured Git properly (see @ref{Configuring
644 Git}). Check that your changes meet the requirements described in
645 @ref{Code style} and/or @ref{Documentation policy}. For advanced
646 edits, you may also want to verify that the changes don't break
647 the compilation process.
650 Run the following command:
657 to make sure you're on the right branch, and to see which files
658 have been modified, added or removed, etc. You may need to tell
659 Git about any files you've added by running one of these:
662 git add @var{file} # add untracked @var{file} individually
663 git add . # add all untracked files in current directory
667 After @command{git@tie{}add}, run @command{git@tie{}status} again
668 to make sure you got everything. You may also need to modify
672 Preview the changes about to be committed (to make sure everything
680 The @code{HEAD} argument refers to the most recent commit on the
681 currently checked-out branch.
684 Generate the commit with:
691 The @code{-a} is short for @code{--all} which includes modified
692 and deleted files, but only those newly created files that have
693 previously been added.
698 @node Commit messages
699 @unnumberedsubsubsec Commit messages
702 When you run the @command{git@tie{}commit@tie{}-a} command, Git
703 automatically opens the default text editor so you can enter a
704 @emph{commit message}. If you find yourself in a foreign editing
705 environment, you're probably in @command{vi} or @command{vim}. If
706 you want to switch to an editor you're more familiar with, quit by
707 typing @code{:q!} and pressing @code{<Enter>}. See
708 @ref{Configuring Git} for instructions on changing the default
711 In any case, Git will open a text file for your commit message
712 that looks like this:
716 # Please enter the commit message for your changes. Lines starting
717 # with '#' will be ignored, and an empty message aborts the commit.
719 # Changes to be committed:
720 # (use "git reset HEAD <file>..." to unstage)
722 # modified: working.itexi
726 Your commit message should begin with a one-line summary
727 describing the change (no more than 50 characters long), and if
728 necessary a blank line followed by several lines giving the
731 @c $ git log -1 --pretty=medium 4d6f1e5
733 Doc: add Baerenreiter and Henle solo cello suites
735 Added comparison of solo cello suite engravings to new essay with
736 high-res images, fixed cropping on Finale example.
739 Commit messages often start with a short prefix describing the
740 general location of the changes. If a commit affects the
741 documentation in English (or in several languages simultaneously)
742 the commit message should be prefixed with @qq{Doc:@tie{}}. If
743 the commit affects only one of the translations, the commit
744 message should be prefixed with @qq{Doc-@var{**}:@tie{}}, where
745 @var{**} is the two-letter language code. Commits that affect the
746 website should use @qq{Web:@tie{}} for English, and
747 @qq{Web-@var{**}:@tie{}} for the other languages. Also, changes
748 to a single file are often prefixed with the name of the file
749 involved. Visit the links listed in @ref{Understanding commits}
754 @unnumberedsubsubsec Making patches
757 If you want to share your changes with other contributors and
758 developers, you need to generate @emph{patches} from your commits.
759 You should always run @command{git@tie{}pull@tie{}-r} (translators
760 should leave off the @code{-r}) before doing this to ensure that
761 your patches are as current as possible.
763 Once you have made one or more commits in your local repository,
764 and pulled the most recent commits from the remote branch, you can
765 generate patches from your local commits with the command:
768 git format-patch origin
771 The @code{origin} argument refers to the remote tracking branch at
772 @code{git.sv.gnu.org}. This command generates a separate patch
773 for each commit that's in the current branch but not in the remote
774 branch. Patches are placed in the current working directory and
775 will have names that look something like this:
778 0001-Doc-Fix-typos.patch
779 0002-Web-Remove-dead-links.patch
783 Send an email to @email{lilypond-devel@@gnu.org} briefly
784 explaining your work, with the patch files attached. Translators
785 should send patches to @email{translations@@lilynet.net}. After
786 your patches are reviewed, the developers may push one or more of
787 them to the main repository or discuss them with you.
791 If your patch includes a significant amount of code, you may want
792 to see @ref{Adding or modifying features}, especially @emph{Post
796 @node Advanced Git procedures
797 @section Advanced Git procedures
800 @warning{This section is not necessary for normal contributors;
801 these commands are presented for information for people interested
802 in learning more about git.}
804 It is possible to work with several branches on the same local Git
805 repository; this is especially useful for translators who may have
806 to deal with both @code{lilypond/translation} and a stable branch,
807 e.g. @code{stable/2.12}.
809 Some Git commands are introduced first, then a workflow with
810 several Git branches of LilyPond source code is presented.
814 * Advanced Git concepts::
815 * Resolving conflicts::
816 * Reverting all local changes::
817 * Working with remote branches::
819 * Applying remote patches::
820 * Sending and receiving patches via email::
825 @node Advanced Git concepts
826 @subsection Advanced Git concepts
829 A bit of Git vocabulary will be explained below. The following is
830 only introductory; for a better understanding of Git concepts, you
831 may wish to read @ref{Other Git documentation}.
833 The @code{git@tie{}pull@tie{}origin} command above is just a
834 shortcut for this command:
837 git pull git://git.sv.gnu.org/lilypond.git/ @var{branch}:origin/@var{branch}
841 where @code{@var{branch}} is typically @code{master} or
842 @code{lilypond/translation}; if you do not know or remember, see
843 @ref{Downloading remote branches} to remember which commands you
844 issued or which source code you wanted to get.
846 A @emph{commit} is a set of changes made to the sources; it also
847 includes the committish of the parent commit, the name and e-mail
848 of the @emph{author} (the person who wrote the changes), the name
849 and e-mail of the @emph{committer} (the person who brings these
850 changes into the Git repository), and a commit message.
852 A @emph{committish} is the SHA1 checksum of a commit, a number
853 made of 40 hexadecimal digits, which acts as the internal unique
854 identifier for this commit. To refer to a particular revision,
855 don't use vague references like the (approximative) date, simply
856 copy and paste the committish.
858 A @emph{branch} is nothing more than a pointer to a particular
859 commit, which is called the @emph{head} of the branch; when
860 referring to a branch, one often acutally thinks about its head
861 and the ancestor commits of the head.
863 Now we will explain the two last commands you used to get the
864 source code from Git---see @ref{Downloading individual branches}.
867 git remote add -ft @var{branch} -m @var{branch} \
868 origin git://git.sv.gnu.org/lilypond.git/
870 git checkout -b @var{branch} origin/@var{branch}
873 The @command{git@tie{}remote} has created a branch called
874 @code{origin/@var{branch}} in your local Git repository. As this
875 branch is a copy of the remote branch web from git.sv.gnu.org
876 LilyPond repository, it is called a @emph{remote branch}, and is
877 meant to track the changes on the branch from git.sv.gnu.org: it
878 will be updated every time you run
879 @command{git@tie{}pull@tie{}origin} or
880 @command{git@tie{}fetch@tie{}origin}.
882 The @command{git@tie{}checkout} command has created a branch named
883 @code{@var{branch}}. At the beginning, this branch is identical
884 to @code{origin/@var{branch}}, but it will differ as soon as you
885 make changes, e.g. adding newly translated pages or editing some
886 documentation or code source file. Whenever you pull, you merge
887 the changes from @code{origin/@var{branch}} and
888 @code{@var{branch}} since the last pulling. If you do not have
889 push (i.e. @qq{write}) access on git.sv.gnu.org, your
890 @code{@var{branch}} will always differ from
891 @code{origin/@var{branch}}. In this case, remember that other
892 people working like you with the remote branch @code{@var{branch}}
893 of git://git.sv.gnu.org/lilypond.git/ (called
894 @code{origin/@var{branch}} on your local repository) know nothing
895 about your own @code{@var{branch}}: this means that whenever you
896 use a committish or make a patch, others expect you to take the
897 latest commit of @code{origin/@var{branch}} as a reference.
899 Finally, please remember to read the man page of every Git command
900 you will find in this manual in case you want to discover
901 alternate methods or just understand how it works.
904 @node Resolving conflicts
905 @subsection Resolving conflicts
908 Occasionally an update may result in conflicts -- this happens
909 when you and somebody else have modified the same part of the same
910 file and git cannot figure out how to merge the two versions
911 together. When this happens, you must manually merge the two
914 If you need some documentation to understand and resolve
915 conflicts, see paragraphs @emph{How conflicts are presented} and
916 @emph{How to resolve conflicts} in @command{git merge} man page.
918 If all else fails, you can follow the instructions in
919 @ref{Reverting all local changes}. Be aware that this eliminates
920 any changes you have made!
923 @node Reverting all local changes
924 @subsection Reverting all local changes
926 Sometimes git will become hopelessly confused, and you just want
927 to get back to a known, stable state. This command destroys any
928 local changes you have made, but at least you get back to the
929 current online version:
932 git reset --hard origin/master
936 @node Working with remote branches
937 @subsection Working with remote branches
940 @subsubheading Fetching new branches from git.sv.gnu.org
942 To fetch and check out a new branch named @code{@var{branch}} on
943 git.sv.gnu.org, run from top of the Git repository
946 git config --add remote.origin.fetch \
947 +refs/heads/@var{branch}:refs/remotes/origin/@var{branch}
949 git checkout --track -b @var{branch} origin/@var{branch}
952 After this, you can pull @code{@var{branch}} from git.sv.gnu.org
959 Note that this command generally fetches all branches you added
960 with @command{git@tie{}remote@tie{}add} (when you initialized the
961 repository) or @command{git@tie{}config@tie{}--add}, i.e. it
962 updates all remote branches from remote @code{origin}, then it
963 merges the remote branch tracked by the current branch into the
964 current branch. For example, if your current branch is
965 @code{master}, @code{origin/master} will be merged into
969 @subsubheading Local clones, or having several working trees
971 If you play with several Git branches, e.g. @code{master},
972 @code{lilypond/translation}, @code{stable/2.12}), you may want to
973 have one source and build tree for each branch; this is possible
974 with subdirectories of your local Git repository, used as local
975 cloned subrepositories. To create a local clone for the branch
976 named @code{@var{branch}}, run
979 git checkout @var{branch}
980 git clone -lsn . @var{subdir}
985 Note that @code{@var{subdir}} must be a directory name which does
986 not already exist. In @code{@var{subdir}}, you can use all Git
987 commands to browse revisions history, commit and uncommit changes;
988 to update the cloned subrepository with changes made on the main
989 repository, cd into @code{@var{subdir}} and run
990 @command{git@tie{}pull}; to send changes made on the subrepository
991 back to the main repository, run @command{git@tie{}push} from
992 @code{@var{subdir}}. Note that only one branch (the currently
993 checked out branch) is created in the subrepository by default; it
994 is possible to have several branches in a subrepository and do
995 usual operations (checkout, merge, create, delete...) on these
996 branches, but this possibility is not detailed here.
998 When you push @code{@var{branch}} from @code{@var{subdir}} to the
999 main repository, and @code{@var{branch}} is checked out in the
1000 main repository, you must save uncommitted changes (see
1001 @command{git@tie{}stash}) and do
1002 @command{git@tie{}reset@tie{}--hard} in the main repository in
1003 order to apply pushed changes in the working tree of the main
1011 The commands above don't only bring you the latest version of the
1012 sources, but also the full history of revisions (revisons, also
1013 called commits, are changes made to the sources), stored in the
1014 @file{.git} directory. You can browse this history with
1017 git log # only shows the logs (author, committish and commit message)
1018 git log -p # also shows diffs
1019 gitk # shows history graphically
1022 @warning{The @code{gitk} command may require a separate
1023 @code{gitk} package, available in the appropriate distribution's
1027 @node Applying remote patches
1028 @subsection Applying remote patches
1031 FIXME: Explain how to determine if a patch was created with
1032 @code{git@tie{}format-patch}.
1034 Well-formed git patches created with @code{git@tie{}format-patch}
1035 should be committed with the following command:
1041 Patches created without @code{git@tie{}format-patch} can be
1042 applied in two steps. The first step is to apply the patch to the
1046 git apply @var{patch}
1050 The second step is to commit the changes and give credit to the
1051 author of the patch. This can be done with the following command:
1054 git commit -a --author="@var{John Smith} <@var{john@@example.com}>"
1058 @node Sending and receiving patches via email
1059 @subsection Sending and receiving patches via email
1062 The default @code{x-diff} MIME type associated with patch files
1063 (i.e., files whose name ends in @code{.patch}) means that the
1064 encoding of line endings may be changed from UNIX to DOS format
1065 when they are sent as attachments. Attempting to apply such an
1066 inadvertently altered patch will cause git to fail with a message
1067 about @q{whitespace errors}.
1069 The solution to such problems is surprisingly simple---just change
1070 the default file extension of patches generated by git to end in
1071 @code{.txt}, for example:
1074 git config format.suffix '.patch.txt'
1077 This should cause email programs to apply the correct base64
1078 encoding to attached patches.
1080 If you receive a patch with DOS instead of UNIX line-endings, it
1081 can be converted back using the @code{dos2unix} utility.
1083 Lots of useful information on email complications with patches is
1084 provided on the Wine wiki at
1085 @uref{http://wiki.winehq.org/GitWine}.
1089 @subsection Commit access
1092 Most contributors are not able to commit patches directly to the
1093 main repository---only members of the LilyPond development team
1094 have @emph{commit access}. If you are a contributor and are
1095 interested in joining the development team, contact the Project
1096 Manager through the mailing list
1097 (@email{lilypond-devel@@gnu.org}). Generally, only contributors
1098 who have already provided a number of patches which have been
1099 pushed to the main repository will be considered for membership.
1101 If you have been approved by the Project Manager, use the
1102 following procedure to obtain commit access:
1106 If you don't already have one, set up a Savannah user account at
1107 @uref{https://savannah.gnu.org/account/register.php}. If your web
1108 browser responds with an @qq{untrusted connection} message when
1109 you visit the link, follow the steps for including the CAcert root
1110 certificate in your browser, given at
1111 @uref{http://savannah.gnu.org/tls/tutorial/}.
1114 After registering, if you are not logged in automatically, login
1115 at @uref{https://savannah.gnu.org/account/login.php}---this should
1116 take you to your @qq{my} page
1117 (@uref{https://savannah.gnu.org/my/}).
1120 Click on the @qq{My Groups} link to access the @qq{My Group
1121 Membership} page. From there, find the @qq{Request for Inclusion}
1122 box and search for @qq{LilyPond}. Among the search results, check
1123 the box labeled @qq{GNU LilyPond Music Typesetter} and write a
1124 brief (required) message for the Project Manager (@qq{Hey it's
1125 me!} should be fine).
1127 Note that you will not have commit access until the Project
1128 Manager activates your membership. Once your membership is
1129 activated, LilyPond should appear under the heading @qq{Groups I'm
1130 Contributor of} on your @qq{My Group Membership} page.
1133 Go to the @qq{My Account Configuration} page. From there, click
1134 on @qq{Edit SSH Keys} and follow the instructions given.
1136 FIXME: Explain the confusing warning I always get. -mp
1138 FIXME: Maybe add a note about enabling/disabling SSH passphrase?
1141 Configure Git to use the SSH protocol (instead of the GIT
1142 protocol). From your local Git repository, enter:
1145 git config remote.origin.url \
1146 ssh://@var{user}@@git.sv.gnu.org/srv/git/lilypond.git
1150 where @var{user} is your username on Savannah.
1153 After your membership has been activated and you've configured Git
1154 to use SSH, try doing a @command{git@tie{}pull} or
1155 @command{git@tie{}pull@tie{}-r}. If that succeeds, this indicates
1156 that your SSH key stored at Savannah is working properly.
1158 FIXME: show what success/failure look like.
1161 Test your commit access with a dry run:
1164 git push --dry-run --verbose
1167 Note that recent versions of Git (Git 1.6.3 or later) will issue a
1168 big warning if the above command is used. The simplest solution
1169 is to tell Git to push all matching branches by default:
1172 git config push.default matching
1176 Then @code{git@tie{}push} should work as before. For more
1177 details, consult the @code{git@tie{}push} man page.
1181 @subsubheading Technical details
1185 On Firefox, to view or remove the CAcert root certificate, go to:
1186 Edit > Preferences > Advanced > Encryption > View Certificates >
1187 Authorities > Certificate Name > Root CA > CA Cert Signing
1191 The @command{git@tie{}config} commands above should modify your
1192 local repository's @file{.git/config} file. These lines:
1196 url = git://git.sv.gnu.org/lilypond.git/
1200 should now be changed to:
1204 url = ssh://@var{user}@@git.sv.gnu.org/srv/git/lilypond.git
1208 where @var{user} is your login name on Savannah.
1212 @command{git@tie{}config@tie{}push.default@tie{}matching} command
1213 should add these lines to @file{.git/config}:
1221 @node Git on Windows
1222 @section Git on Windows
1224 @c Some of this may duplicate stuff in other sections
1225 @c But it is probably best for windows users to have it all together
1226 @c If necessary, clear this up later -td
1228 FIXME: Decide what to do with this... Pare it down? Move
1229 paragraphs next to analogous Unix instructions? -mp
1231 @subsection Background to nomenclature
1233 Git is a system for tracking the changes made to source files by a
1234 distributed set of editors. It is designed to work without a
1235 master repository, but we have chosen to have a master respository
1236 for LilyPond files. Editors hold a local copy of the master
1237 repository together with any changes they have made locally.
1238 Local changes are held in a local @q{branch}, of which there may
1239 be several, but these instructions assume you are using just one.
1240 The files visible in the local repository always correspond to
1241 those on the currently @q{checked out} local branch.
1243 Files are edited on a local branch, and in that state the changes
1244 are said to be @q{unstaged}. When editing is complete, the
1245 changes are moved to being @q{staged for commit}, and finally the
1246 changes are @q{committed} to the local branch. Once committed,
1247 the changes (called a @q{commit}) are given a unique 40-digit
1248 hexadecimal reference number called the @q{Committish} or @q{SHA1
1249 ID} which identifies the commit to Git. Such committed changes
1250 can be sent to the master repository by @q{pushing} them (if you
1251 have write permission) or by sending them by email to someone who
1252 has, either as a complete file or as a @q{diff} or @q{patch}
1253 (which send just the differences from the master repository).
1255 @subsection Installing git
1258 @uref{http://code.google.com/p/msysgit/downloads/list} (note, not
1259 msysGit, which is for Git developers and not PortableGit, which is
1260 not a full git installation) and install it.
1262 Note that most users will not need to install SSH. That is not
1263 required until you have been granted direct push permissions to
1264 the master git repository.
1266 Start Git by clicking on the desktop icon. This will bring up a
1267 command line bash shell. This may be unfamiliar to Windows users.
1268 If so, follow these instructions carefully. Commands are entered
1269 at a $ prompt and are terminated by keying a newline.
1271 @subsection Initialising Git
1273 Decide where you wish to place your local Git repository, creating
1274 the folders in Windows as necessary. Here we call the folder to
1275 contain the repository @code{[path]/Git}, but if you intend using
1276 Git for other projects a directory name like @code{lilypond-git}
1277 might be better. You will need to have space for around
1280 Start the Git bash shell by clicking on the desk-top icon
1281 installed with Git and type
1287 to position the shell at your new Git repository.
1289 Note: if [path] contains folders with names containing spaces use
1301 to initialize your Git repository.
1303 Then type (all on one line; the shell will wrap automatically)
1306 git remote add -ft master origin git://git.sv.gnu.org/lilypond.git
1309 to download the lilypond master files.
1311 @warning{Be patient! Even on a broadband connection this can take
1312 10 minutes or more. Wait for lots of [new tag] messages and the $
1315 We now need to generate a local copy of the downloaded files in a
1316 new local branch. Your local branch needs to have a name. It is
1317 usual to call it @q{master} and we shall do that here.
1322 git checkout -b master origin/master
1325 This creates a second branch called @q{master}. You will see two
1326 warnings (ignore these), and a message advising you that your
1327 local branch @q{master} has been set up to track the remote
1328 branch. You now have two branches, a local branch called
1329 @q{master}, and a tracking branch called @q{origin/master}, which
1330 is a shortened form of @q{remotes/origin/master}.
1332 Return to Windows Explorer and look in your Git repository. You
1333 should see lots of folders. For example, the LilyPond
1334 documentation can be found in [path]/Git/Documentation/.
1336 The Git bash shell is terminated by typing @code{exit} or by
1337 clicking on the usual Windows close-window widget.
1341 Almost all subsequent work will use the Git Graphical User
1342 Interface, which avoids having to type command line commands. To
1343 start Git GUI first start the Git bash shell by clicking on the
1344 desktop icon, and type
1351 The Git GUI will open in a new window. It contains four panels
1352 and 7 pull-down menus. At this stage do not use any of the
1353 commands under Branch, Commit, Merge or Remote. These will be
1356 The top panel on the left contains the names of files which you
1357 are in the process of editing (Unstaged Changes), and the lower
1358 panel on the left contains the names of files you have finished
1359 editing and have staged ready for committing (Staged Changes). At
1360 present, these panels will be empty as you have not yet made any
1361 changes to any file. After a file has been edited and saved the
1362 top panel on the right will display the differences between the
1363 edited file selected in one of the panels on the left and the last
1364 version committed on the current branch.
1366 The panel at bottom right is used to enter a descriptive message
1367 about the change before committing it.
1369 The Git GUI is terminated by entering CNTL-Q while it is the
1370 active window or by clicking on the usual Windows close-window
1373 @subsection Personalising your local git repository
1375 Open the Git GUI, click on
1381 and enter your name and email address in the left-hand (Git
1382 Repository) panel. Leave everything else unchanged and save it.
1384 Note that Windows users must leave the default setting for line
1385 endings unchanged. All files in a git repository must have lines
1386 terminated by just a LF, as this is required for Merge to work,
1387 but Windows files are terminated by CRLF by default. The git
1388 default setting causes the line endings of files in a Windows git
1389 repository to be flipped automatically between LF and CRLF as
1390 required. This enables files to be edited by any Windows editor
1391 without causing problems in the git repository.
1393 @subsection Checking out a branch
1395 At this stage you have two branches in your local repository,
1396 both identical. To see them click on
1402 You should have one local branch called @q{master} and one
1403 tracking branch called @q{origin/master}. The latter is your
1404 local copy of the @q{remotes/origin/master} branch in the master
1405 LilyPond repository. The local @q{master} branch is where you
1406 will make your local changes.
1408 When a particular branch is selected, i.e., checked out, the files
1409 visible in your repository are changed to reflect the state of the
1410 files on that branch.
1412 @subsection Updating files from @q{remote/origin/master}
1414 Before starting the editing of a file, ensure your local
1415 repository contains the latest version of the files in the remote
1416 repository by first clicking
1419 Remote -> Fetch from -> origin
1425 This will place the latest version of every file, including all
1426 the changes made by others, into the @q{origin/master} branch of
1427 the tracking branches in your git repository. You can see these
1428 files by checking out this branch, but you must @emph{never} edit
1429 any files while this branch is checked out. Check out your local
1430 @q{master} branch again.
1432 You then need to merge these fetched files into your local
1433 @q{master} branch by clicking on
1436 Merge -> Local Merge
1440 and if necessary select the local @q{master} branch.
1442 Note that a merge cannot be completed if you have made any local
1443 changes which have not yet been committed.
1445 This merge will update all the files in the @q{master} branch to
1446 reflect the current state of the @q{origin/master} branch. If any
1447 of the changes conflict with changes you have made yourself
1448 recently you will be notified of the conflict (see below).
1450 @subsection Editing files
1452 First ensure your @q{master} branch is checked out, then simply
1453 edit the files in your local Git repository with your favourite
1454 editor and save them back there. If any file contains non-ASCII
1455 characters ensure you save it in UTF-8 format. Git will detect
1456 any changes whenever you restart Git GUI and the file names will
1457 then be listed in the Unstaged Changes panel. Or you can click
1458 the Rescan button to refresh the panel contents at any time. You
1459 may break off and resume editing any time.
1461 The changes you have made may be displayed in diff form in the top
1462 right-hand panel of Git GUI by clicking on the file name shown in
1463 one of the left panels.
1465 When your editing is complete, move the files from being Unstaged
1466 to Staged by clicking the document symbol to the left of each
1467 name. If you change your mind it can be moved back by clicking on
1468 the ticked box to the left of the name.
1470 Finally the changes you have made may be committed to your
1471 @q{master} branch by entering a brief message in the Commit
1472 Message box and clicking the Commit button.
1474 If you wish to amend your changes after a commit has been made,
1475 the original version and the changes you made in that commit may
1476 be recovered by selecting
1479 Commit -> Amend Last Commit
1483 or by checking the Amend Last Commit radio button at bottom right.
1484 This will return the changes to the Staged state, so further
1485 editing made be carried out within that commit. This must only be
1486 done @emph{before} the changes have been Pushed or sent to your
1487 mentor for Pushing - after that it is too late and corrections
1488 have to be made as a separate commit.
1491 @subsection Sending changes to @q{remotes/origin/master}
1493 If you do not have write access to @q{remotes/origin/master} you
1494 will need to send your changes by email to someone who does.
1496 First you need to create a diff or patch file containing your
1497 changes. To create this, the file must first be committed. Then
1498 terminate the Git GUI. In the git bash shell first cd to your Git
1505 if necessary, then produce the patch with
1508 git format-patch origin
1511 This will create a patch file for all the locally committed files
1512 which differ from @q{origin/master}. The patch file can be found
1513 in [path]/Git and will have a name formed from the commit message.
1515 @subsection Resolving merge conflicts
1517 As soon as you have committed a changed file your local
1518 @code{master} branch has diverged from @code{origin/master}, and
1519 will remain diverged until your changes have been committed in
1520 @code{remotes/origin/master} and Fetched back into your
1521 @code{origin/master} branch. Similarly, if a new commit has been
1522 made to @code{remotes/origin/master} by someone else and Fetched,
1523 your local @code{master} branch is divergent. You can detect a
1524 divergent branch by clicking on
1527 Repository -> Visualise all branch history
1530 This opens up a very useful new window called @q{gitk}. Use this
1531 to browse all the commits made by yourself and others.
1533 If the diagram at top left of the resulting window does not show
1534 your @code{master} tag on the same node as the
1535 @code{remotes/origin/master} tag your branch has diverged from
1536 @code{origin/master}. This is quite normal if files you have
1537 modified yourself have not yet been Pushed to
1538 @code{remotes/origin/master} and Fetched, or if files modified and
1539 committed by others have been Fetched since you last Merged
1540 @code{origin/master} into your local @code{master} branch.
1542 If a file being merged from @code{origin/master} differs from one
1543 you have modified in a way that cannot be resolved automatically
1544 by git, Merge will report a Conflict which you must resolve by
1545 editing the file to create the version you wish to keep.
1547 This could happen if the person updating
1548 @code{remotes/origin/master} for you has added some changes of his
1549 own before committing your changes to
1550 @code{remotes/origin/master}, or if someone else has changed the
1551 same file since you last fetched the file from
1552 @code{remotes/origin/master}.
1554 Open the file in your editor and look for sections which are
1557 [to be completed when I next have a merge conflict to be sure I
1558 give the right instructions -td]
1561 @subsection Other actions
1563 The instructions above describe the simplest way of using git on
1564 Windows. Other git facilities which may usefully supplement these
1568 @item Using multiple local branches (Create, Rename, Delete)
1569 @item Resetting branches
1570 @item Cherry-picking commits
1571 @item Pushing commits to @w{remote/origin/master}
1572 @item Using gitk to review history
1575 Once familiarity with using git on Windows has been gained the
1576 standard git manuals can be used to learn about these.
1579 @node Repository directory structure
1580 @section Repository directory structure
1583 @c TODO: integrate the roadmap better
1584 @verbatiminclude ROADMAP
1587 @node Other Git documentation
1588 @section Other Git documentation
1592 Official git man pages:
1593 @uref{http://www.kernel.org/pub/software/scm/git/docs/}
1596 More in-depth tutorials: @uref{http://git-scm.com/documentation}
1599 Book about git: @uref{http://progit.org/,Pro Git}