1 @c -*- coding: us-ascii; 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 not newly created files.
696 @node Commit messages
697 @unnumberedsubsubsec Commit messages
700 When you run the @command{git@tie{}commit@tie{}-a} command, Git
701 automatically opens the default text editor so you can enter a
702 @emph{commit message}. If you find yourself in a foreign editing
703 environment, you're probably in @command{vi} or @command{vim}. If
704 you want to switch to an editor you're more familiar with, quit by
705 typing @code{:q!} and pressing @code{<Enter>}. See
706 @ref{Configuring Git} for instructions on changing the default
709 In any case, Git will open a text file for your commit message
710 that looks like this:
714 # Please enter the commit message for your changes. Lines starting
715 # with '#' will be ignored, and an empty message aborts the commit.
717 # Changes to be committed:
718 # (use "git reset HEAD <file>..." to unstage)
720 # modified: working.itexi
724 Your commit message should begin with a one-line summary
725 describing the change (no more than 50 characters long), and if
726 necessary a blank line followed by several lines giving the
729 @c $ git log -1 --pretty=medium 4d6f1e5
731 Doc: add Baerenreiter and Henle solo cello suites
733 Added comparison of solo cello suite engravings to new essay with
734 high-res images, fixed cropping on Finale example.
737 Commit messages often start with a short prefix describing the
738 general location of the changes. If a commit affects the
739 documentation in English (or in several languages simultaneously)
740 the commit message should be prefixed with @qq{Doc:@tie{}}. If
741 the commit affects only one of the translations, the commit
742 message should be prefixed with @qq{Doc-@var{**}:@tie{}}, where
743 @var{**} is the two-letter language code. Commits that affect the
744 website should use @qq{Web:@tie{}} for English, and
745 @qq{Web-@var{**}:@tie{}} for the other languages. Also, changes
746 to a single file are often prefixed with the name of the file
747 involved. Visit the links listed in @ref{Understanding commits}
752 @unnumberedsubsubsec Making patches
755 If you want to share your changes with other contributors and
756 developers, you need to generate @emph{patches} from your commits.
757 You should always run @command{git@tie{}pull@tie{}-r} (translators
758 should leave off the @code{-r}) before doing this to ensure that
759 your patches are as current as possible.
761 Once you have made one or more commits in your local repository,
762 and pulled the most recent commits from the remote branch, you can
763 generate patches from your local commits with the command:
766 git format-patch origin
769 The @code{origin} argument refers to the remote tracking branch at
770 @code{git.sv.gnu.org}. This command generates a separate patch
771 for each commit that's in the current branch but not in the remote
772 branch. Patches are placed in the current working directory and
773 will have names that look something like this:
776 0001-Doc-Fix-typos.patch
777 0002-Web-Remove-dead-links.patch
781 Send an email to @email{lilypond-devel@@gnu.org} briefly
782 explaining your work, with the patch files attached. Translators
783 should send patches to @email{translations@@lilynet.net}. After
784 your patches are reviewed, the developers may push one or more of
785 them to the main repository or discuss them with you.
789 If your patch includes a significant amount of code, you may want
790 to see @ref{Adding or modifying features}, especially @emph{Post
794 @node Advanced Git procedures
795 @section Advanced Git procedures
798 @warning{This section is not necessary for normal contributors;
799 these commands are presented for information for people interested
800 in learning more about git.}
802 It is possible to work with several branches on the same local Git
803 repository; this is especially useful for translators who may have
804 to deal with both @code{lilypond/translation} and a stable branch,
805 e.g. @code{stable/2.12}.
807 Some Git commands are introduced first, then a workflow with
808 several Git branches of LilyPond source code is presented.
812 * Advanced Git concepts::
813 * Resolving conflicts::
814 * Reverting all local changes::
815 * Working with remote branches::
817 * Applying remote patches::
822 @node Advanced Git concepts
823 @subsection Advanced Git concepts
826 A bit of Git vocabulary will be explained below. The following is
827 only introductory; for a better understanding of Git concepts, you
828 may wish to read @ref{Other Git documentation}.
830 The @code{git@tie{}pull@tie{}origin} command above is just a
831 shortcut for this command:
834 git pull git://git.sv.gnu.org/lilypond.git/ @var{branch}:origin/@var{branch}
838 where @code{@var{branch}} is typically @code{master} or
839 @code{lilypond/translation}; if you do not know or remember, see
840 @ref{Downloading remote branches} to remember which commands you
841 issued or which source code you wanted to get.
843 A @emph{commit} is a set of changes made to the sources; it also
844 includes the committish of the parent commit, the name and e-mail
845 of the @emph{author} (the person who wrote the changes), the name
846 and e-mail of the @emph{committer} (the person who brings these
847 changes into the Git repository), and a commit message.
849 A @emph{committish} is the SHA1 checksum of a commit, a number
850 made of 40 hexadecimal digits, which acts as the internal unique
851 identifier for this commit. To refer to a particular revision,
852 don't use vague references like the (approximative) date, simply
853 copy and paste the committish.
855 A @emph{branch} is nothing more than a pointer to a particular
856 commit, which is called the @emph{head} of the branch; when
857 referring to a branch, one often acutally thinks about its head
858 and the ancestor commits of the head.
860 Now we will explain the two last commands you used to get the
861 source code from Git---see @ref{Downloading individual branches}.
864 git remote add -ft @var{branch} -m @var{branch} \
865 origin git://git.sv.gnu.org/lilypond.git/
867 git checkout -b @var{branch} origin/@var{branch}
870 The @command{git@tie{}remote} has created a branch called
871 @code{origin/@var{branch}} in your local Git repository. As this
872 branch is a copy of the remote branch web from git.sv.gnu.org
873 LilyPond repository, it is called a @emph{remote branch}, and is
874 meant to track the changes on the branch from git.sv.gnu.org: it
875 will be updated every time you run
876 @command{git@tie{}pull@tie{}origin} or
877 @command{git@tie{}fetch@tie{}origin}.
879 The @command{git@tie{}checkout} command has created a branch named
880 @code{@var{branch}}. At the beginning, this branch is identical
881 to @code{origin/@var{branch}}, but it will differ as soon as you
882 make changes, e.g. adding newly translated pages or editing some
883 documentation or code source file. Whenever you pull, you merge
884 the changes from @code{origin/@var{branch}} and
885 @code{@var{branch}} since the last pulling. If you do not have
886 push (i.e. @qq{write}) access on git.sv.gnu.org, your
887 @code{@var{branch}} will always differ from
888 @code{origin/@var{branch}}. In this case, remember that other
889 people working like you with the remote branch @code{@var{branch}}
890 of git://git.sv.gnu.org/lilypond.git/ (called
891 @code{origin/@var{branch}} on your local repository) know nothing
892 about your own @code{@var{branch}}: this means that whenever you
893 use a committish or make a patch, others expect you to take the
894 latest commit of @code{origin/@var{branch}} as a reference.
896 Finally, please remember to read the man page of every Git command
897 you will find in this manual in case you want to discover
898 alternate methods or just understand how it works.
901 @node Resolving conflicts
902 @subsection Resolving conflicts
905 Occasionally an update may result in conflicts -- this happens
906 when you and somebody else have modified the same part of the same
907 file and git cannot figure out how to merge the two versions
908 together. When this happens, you must manually merge the two
911 If you need some documentation to understand and resolve
912 conflicts, see paragraphs @emph{How conflicts are presented} and
913 @emph{How to resolve conflicts} in @command{git merge} man page.
915 If all else fails, you can follow the instructions in
916 @ref{Reverting all local changes}. Be aware that this eliminates
917 any changes you have made!
920 @node Reverting all local changes
921 @subsection Reverting all local changes
923 Sometimes git will become hopelessly confused, and you just want
924 to get back to a known, stable state. This command destroys any
925 local changes you have made, but at least you get back to the
926 current online version:
929 git reset --hard origin/master
933 @node Working with remote branches
934 @subsection Working with remote branches
937 @subsubheading Fetching new branches from git.sv.gnu.org
939 To fetch and check out a new branch named @code{@var{branch}} on
940 git.sv.gnu.org, run from top of the Git repository
943 git config --add remote.origin.fetch \
944 +refs/heads/@var{branch}:refs/remotes/origin/@var{branch}
946 git checkout --track -b @var{branch} origin/@var{branch}
949 After this, you can pull @code{@var{branch}} from git.sv.gnu.org
956 Note that this command generally fetches all branches you added
957 with @command{git@tie{}remote@tie{}add} (when you initialized the
958 repository) or @command{git@tie{}config@tie{}--add}, i.e. it
959 updates all remote branches from remote @code{origin}, then it
960 merges the remote branch tracked by the current branch into the
961 current branch. For example, if your current branch is
962 @code{master}, @code{origin/master} will be merged into
966 @subsubheading Local clones, or having several working trees
968 If you play with several Git branches, e.g. @code{master},
969 @code{lilypond/translation}, @code{stable/2.12}), you may want to
970 have one source and build tree for each branch; this is possible
971 with subdirectories of your local Git repository, used as local
972 cloned subrepositories. To create a local clone for the branch
973 named @code{@var{branch}}, run
976 git checkout @var{branch}
977 git clone -lsn . @var{subdir}
982 Note that @code{@var{subdir}} must be a directory name which does
983 not already exist. In @code{@var{subdir}}, you can use all Git
984 commands to browse revisions history, commit and uncommit changes;
985 to update the cloned subrepository with changes made on the main
986 repository, cd into @code{@var{subdir}} and run
987 @command{git@tie{}pull}; to send changes made on the subrepository
988 back to the main repository, run @command{git@tie{}push} from
989 @code{@var{subdir}}. Note that only one branch (the currently
990 checked out branch) is created in the subrepository by default; it
991 is possible to have several branches in a subrepository and do
992 usual operations (checkout, merge, create, delete...) on these
993 branches, but this possibility is not detailed here.
995 When you push @code{@var{branch}} from @code{@var{subdir}} to the
996 main repository, and @code{@var{branch}} is checked out in the
997 main repository, you must save uncommitted changes (see
998 @command{git@tie{}stash}) and do
999 @command{git@tie{}reset@tie{}--hard} in the main repository in
1000 order to apply pushed changes in the working tree of the main
1008 The commands above don't only bring you the latest version of the
1009 sources, but also the full history of revisions (revisons, also
1010 called commits, are changes made to the sources), stored in the
1011 @file{.git} directory. You can browse this history with
1014 git log # only shows the logs (author, committish and commit message)
1015 git log -p # also shows diffs
1016 gitk # shows history graphically
1019 @warning{The @code{gitk} command may require a separate
1020 @code{gitk} package, available in the appropriate distribution's
1024 @node Applying remote patches
1025 @subsection Applying remote patches
1028 FIXME: Explain how to determine if a patch was created with
1029 @code{git@tie{}format-patch}.
1031 Well-formed git patches created with @code{git@tie{}format-patch}
1032 should be committed with the following command:
1038 Patches created without @code{git@tie{}format-patch} can be
1039 applied in two steps. The first step is to apply the patch to the
1043 git apply @var{patch}
1047 The second step is to commit the changes and give credit to the
1048 author of the patch. This can be done with the following command:
1051 git commit -a --author="@var{John Smith} <@var{john@@example.com}>"
1056 @subsection Commit access
1059 Most contributors are not able to commit patches directly to the
1060 main repository---only members of the LilyPond development team
1061 have @emph{commit access}. If you are a contributor and are
1062 interested in joining the development team, contact the Project
1063 Manager through the mailing list
1064 (@email{lilypond-devel@@gnu.org}). Generally, only contributors
1065 who have already provided a number of patches which have been
1066 pushed to the main repository will be considered for membership.
1068 If you have been approved by the Project Manager, use the
1069 following procedure to obtain commit access:
1073 If you don't already have one, set up a Savannah user account at
1074 @uref{https://savannah.gnu.org/account/register.php}. If your web
1075 browser responds with an @qq{untrusted connection} message when
1076 you visit the link, follow the steps for including the CAcert root
1077 certificate in your browser, given at
1078 @uref{http://savannah.gnu.org/tls/tutorial/}.
1081 After registering, if you are not logged in automatically, login
1082 at @uref{https://savannah.gnu.org/account/login.php}---this should
1083 take you to your @qq{my} page
1084 (@uref{https://savannah.gnu.org/my/}).
1087 Click on the @qq{My Groups} link to access the @qq{My Group
1088 Membership} page. From there, find the @qq{Request for Inclusion}
1089 box and search for @qq{LilyPond}. Among the search results, check
1090 the box labeled @qq{GNU LilyPond Music Typesetter} and write a
1091 brief (required) message for the Project Manager (@qq{Hey it's
1092 me!} should be fine).
1094 Note that you will not have commit access until the Project
1095 Manager activates your membership. Once your membership is
1096 activated, LilyPond should appear under the heading @qq{Groups I'm
1097 Contributor of} on your @qq{My Group Membership} page.
1100 Go to the @qq{My Account Configuration} page. From there, click
1101 on @qq{Edit SSH Keys} and follow the instructions given.
1103 FIXME: Explain the confusing warning I always get. -mp
1105 FIXME: Maybe add a note about enabling/disabling SSH passphrase?
1108 Configure Git to use the SSH protocol (instead of the GIT
1109 protocol). From your local Git repository, enter:
1112 git config remote.origin.url \
1113 ssh://@var{user}@@git.sv.gnu.org/srv/git/lilypond.git
1117 where @var{user} is your username on Savannah.
1120 After your membership has been activated and you've configured Git
1121 to use SSH, try doing a @command{git@tie{}pull} or
1122 @command{git@tie{}pull@tie{}-r}. If that succeeds, this indicates
1123 that your SSH key stored at Savannah is working properly.
1125 FIXME: show what success/failure look like.
1128 Test your commit access with a dry run:
1131 git push --dry-run --verbose
1134 Note that recent versions of Git (Git 1.6.3 or later) will issue a
1135 big warning if the above command is used. The simplest solution
1136 is to tell Git to push all matching branches by default:
1139 git config push.default matching
1143 Then @code{git@tie{}push} should work as before. For more
1144 details, consult the @code{git@tie{}push} man page.
1148 @subsubheading Technical details
1152 On Firefox, to view or remove the CAcert root certificate, go to:
1153 Edit > Preferences > Advanced > Encryption > View Certificates >
1154 Authorities > Certificate Name > Root CA > CA Cert Signing
1158 The @command{git@tie{}config} commands above should modify your
1159 local repository's @file{.git/config} file. These lines:
1163 url = git://git.sv.gnu.org/lilypond.git/
1167 should now be changed to:
1171 url = ssh://@var{user}@@git.sv.gnu.org/srv/git/lilypond.git
1175 where @var{user} is your login name on Savannah.
1179 @command{git@tie{}config@tie{}push.default@tie{}matching} command
1180 should add these lines to @file{.git/config}:
1188 @node Git on Windows
1189 @section Git on Windows
1191 @c Some of this may duplicate stuff in other sections
1192 @c But it is probably best for windows users to have it all together
1193 @c If necessary, clear this up later -td
1195 FIXME: Decide what to do with this... Pare it down? Move
1196 paragraphs next to analogous Unix instructions? -mp
1198 @subsection Background to nomenclature
1200 Git is a system for tracking the changes made to source files by a
1201 distributed set of editors. It is designed to work without a
1202 master repository, but we have chosen to have a master respository
1203 for LilyPond files. Editors hold a local copy of the master
1204 repository together with any changes they have made locally.
1205 Local changes are held in a local @q{branch}, of which there may
1206 be several, but these instructions assume you are using just one.
1207 The files visible in the local repository always correspond to
1208 those on the currently @q{checked out} local branch.
1210 Files are edited on a local branch, and in that state the changes
1211 are said to be @q{unstaged}. When editing is complete, the
1212 changes are moved to being @q{staged for commit}, and finally the
1213 changes are @q{committed} to the local branch. Once committed,
1214 the changes (called a @q{commit}) are given a unique 40-digit
1215 hexadecimal reference number called the @q{Committish} or @q{SHA1
1216 ID} which identifies the commit to Git. Such committed changes
1217 can be sent to the master repository by @q{pushing} them (if you
1218 have write permission) or by sending them by email to someone who
1219 has, either as a complete file or as a @q{diff} or @q{patch}
1220 (which send just the differences from the master repository).
1222 @subsection Installing git
1225 @uref{http://code.google.com/p/msysgit/downloads/list} (note, not
1226 msysGit, which is for Git developers and not PortableGit, which is
1227 not a full git installation) and install it.
1229 Note that most users will not need to install SSH. That is not
1230 required until you have been granted direct push permissions to
1231 the master git repository.
1233 Start Git by clicking on the desktop icon. This will bring up a
1234 command line bash shell. This may be unfamiliar to Windows users.
1235 If so, follow these instructions carefully. Commands are entered
1236 at a $ prompt and are terminated by keying a newline.
1238 @subsection Initialising Git
1240 Decide where you wish to place your local Git repository, creating
1241 the folders in Windows as necessary. Here we call the folder to
1242 contain the repository @code{[path]/Git}, but if you intend using
1243 Git for other projects a directory name like @code{lilypond-git}
1244 might be better. You will need to have space for around
1247 Start the Git bash shell by clicking on the desk-top icon
1248 installed with Git and type
1254 to position the shell at your new Git repository.
1256 Note: if [path] contains folders with names containing spaces use
1268 to initialize your Git repository.
1270 Then type (all on one line; the shell will wrap automatically)
1273 git remote add -ft master origin git://git.sv.gnu.org/lilypond.git
1276 to download the lilypond master files.
1278 @warning{Be patient! Even on a broadband connection this can take
1279 10 minutes or more. Wait for lots of [new tag] messages and the $
1282 We now need to generate a local copy of the downloaded files in a
1283 new local branch. Your local branch needs to have a name. It is
1284 usual to call it @q{master} and we shall do that here.
1289 git checkout -b master origin/master
1292 This creates a second branch called @q{master}. You will see two
1293 warnings (ignore these), and a message advising you that your
1294 local branch @q{master} has been set up to track the remote
1295 branch. You now have two branches, a local branch called
1296 @q{master}, and a tracking branch called @q{origin/master}, which
1297 is a shortened form of @q{remotes/origin/master}.
1299 Return to Windows Explorer and look in your Git repository. You
1300 should see lots of folders. For example, the LilyPond
1301 documentation can be found in [path]/Git/Documentation/.
1303 The Git bash shell is terminated by typing @code{exit} or by
1304 clicking on the usual Windows close-window widget.
1308 Almost all subsequent work will use the Git Graphical User
1309 Interface, which avoids having to type command line commands. To
1310 start Git GUI first start the Git bash shell by clicking on the
1311 desktop icon, and type
1318 The Git GUI will open in a new window. It contains four panels
1319 and 7 pull-down menus. At this stage do not use any of the
1320 commands under Branch, Commit, Merge or Remote. These will be
1323 The top panel on the left contains the names of files which you
1324 are in the process of editing (Unstaged Changes), and the lower
1325 panel on the left contains the names of files you have finished
1326 editing and have staged ready for committing (Staged Changes). At
1327 present, these panels will be empty as you have not yet made any
1328 changes to any file. After a file has been edited and saved the
1329 top panel on the right will display the differences between the
1330 edited file selected in one of the panels on the left and the last
1331 version committed on the current branch.
1333 The panel at bottom right is used to enter a descriptive message
1334 about the change before committing it.
1336 The Git GUI is terminated by entering CNTL-Q while it is the
1337 active window or by clicking on the usual Windows close-window
1340 @subsection Personalising your local git repository
1342 Open the Git GUI, click on
1348 and enter your name and email address in the left-hand (Git
1349 Repository) panel. Leave everything else unchanged and save it.
1351 Note that Windows users must leave the default setting for line
1352 endings unchanged. All files in a git repository must have lines
1353 terminated by just a LF, as this is required for Merge to work,
1354 but Windows files are terminated by CRLF by default. The git
1355 default setting causes the line endings of files in a Windows git
1356 repository to be flipped automatically between LF and CRLF as
1357 required. This enables files to be edited by any Windows editor
1358 without causing problems in the git repository.
1360 @subsection Checking out a branch
1362 At this stage you have two branches in your local repository,
1363 both identical. To see them click on
1369 You should have one local branch called @q{master} and one
1370 tracking branch called @q{origin/master}. The latter is your
1371 local copy of the @q{remotes/origin/master} branch in the master
1372 LilyPond repository. The local @q{master} branch is where you
1373 will make your local changes.
1375 When a particular branch is selected, i.e., checked out, the files
1376 visible in your repository are changed to reflect the state of the
1377 files on that branch.
1379 @subsection Updating files from @q{remote/origin/master}
1381 Before starting the editing of a file, ensure your local
1382 repository contains the latest version of the files in the remote
1383 repository by first clicking
1386 Remote -> Fetch from -> origin
1392 This will place the latest version of every file, including all
1393 the changes made by others, into the @q{origin/master} branch of
1394 the tracking branches in your git repository. You can see these
1395 files by checking out this branch, but you must @emph{never} edit
1396 any files while this branch is checked out. Check out your local
1397 @q{master} branch again.
1399 You then need to merge these fetched files into your local
1400 @q{master} branch by clicking on
1403 Merge -> Local Merge
1407 and if necessary select the local @q{master} branch.
1409 Note that a merge cannot be completed if you have made any local
1410 changes which have not yet been committed.
1412 This merge will update all the files in the @q{master} branch to
1413 reflect the current state of the @q{origin/master} branch. If any
1414 of the changes conflict with changes you have made yourself
1415 recently you will be notified of the conflict (see below).
1417 @subsection Editing files
1419 First ensure your @q{master} branch is checked out, then simply
1420 edit the files in your local Git repository with your favourite
1421 editor and save them back there. If any file contains non-ASCII
1422 characters ensure you save it in UTF-8 format. Git will detect
1423 any changes whenever you restart Git GUI and the file names will
1424 then be listed in the Unstaged Changes panel. Or you can click
1425 the Rescan button to refresh the panel contents at any time. You
1426 may break off and resume editing any time.
1428 The changes you have made may be displayed in diff form in the top
1429 right-hand panel of Git GUI by clicking on the file name shown in
1430 one of the left panels.
1432 When your editing is complete, move the files from being Unstaged
1433 to Staged by clicking the document symbol to the left of each
1434 name. If you change your mind it can be moved back by clicking on
1435 the ticked box to the left of the name.
1437 Finally the changes you have made may be committed to your
1438 @q{master} branch by entering a brief message in the Commit
1439 Message box and clicking the Commit button.
1441 If you wish to amend your changes after a commit has been made,
1442 the original version and the changes you made in that commit may
1443 be recovered by selecting
1446 Commit -> Amend Last Commit
1450 or by checking the Amend Last Commit radio button at bottom right.
1451 This will return the changes to the Staged state, so further
1452 editing made be carried out within that commit. This must only be
1453 done @emph{before} the changes have been Pushed or sent to your
1454 mentor for Pushing - after that it is too late and corrections
1455 have to be made as a separate commit.
1458 @subsection Sending changes to @q{remotes/origin/master}
1460 If you do not have write access to @q{remotes/origin/master} you
1461 will need to send your changes by email to someone who does.
1463 First you need to create a diff or patch file containing your
1464 changes. To create this, the file must first be committed. Then
1465 terminate the Git GUI. In the git bash shell first cd to your Git
1472 if necessary, then produce the patch with
1475 git format-patch origin
1478 This will create a patch file for all the locally committed files
1479 which differ from @q{origin/master}. The patch file can be found
1480 in [path]/Git and will have a name formed from the commit message.
1482 @subsection Resolving merge conflicts
1484 As soon as you have committed a changed file your local
1485 @code{master} branch has diverged from @code{origin/master}, and
1486 will remain diverged until your changes have been committed in
1487 @code{remotes/origin/master} and Fetched back into your
1488 @code{origin/master} branch. Similarly, if a new commit has been
1489 made to @code{remotes/origin/master} by someone else and Fetched,
1490 your local @code{master} branch is divergent. You can detect a
1491 divergent branch by clicking on
1494 Repository -> Visualise all branch history
1497 This opens up a very useful new window called @q{gitk}. Use this
1498 to browse all the commits made by yourself and others.
1500 If the diagram at top left of the resulting window does not show
1501 your @code{master} tag on the same node as the
1502 @code{remotes/origin/master} tag your branch has diverged from
1503 @code{origin/master}. This is quite normal if files you have
1504 modified yourself have not yet been Pushed to
1505 @code{remotes/origin/master} and Fetched, or if files modified and
1506 committed by others have been Fetched since you last Merged
1507 @code{origin/master} into your local @code{master} branch.
1509 If a file being merged from @code{origin/master} differs from one
1510 you have modified in a way that cannot be resolved automatically
1511 by git, Merge will report a Conflict which you must resolve by
1512 editing the file to create the version you wish to keep.
1514 This could happen if the person updating
1515 @code{remotes/origin/master} for you has added some changes of his
1516 own before committing your changes to
1517 @code{remotes/origin/master}, or if someone else has changed the
1518 same file since you last fetched the file from
1519 @code{remotes/origin/master}.
1521 Open the file in your editor and look for sections which are
1524 [to be completed when I next have a merge conflict to be sure I
1525 give the right instructions -td]
1528 @subsection Other actions
1530 The instructions above describe the simplest way of using git on
1531 Windows. Other git facilities which may usefully supplement these
1535 @item Using multiple local branches (Create, Rename, Delete)
1536 @item Resetting branches
1537 @item Cherry-picking commits
1538 @item Pushing commits to @w{remote/origin/master}
1539 @item Using gitk to review history
1542 Once familiarity with using git on Windows has been gained the
1543 standard git manuals can be used to learn about these.
1546 @node Repository directory structure
1547 @section Repository directory structure
1550 @c TODO: integrate the roadmap better
1551 @verbatiminclude ROADMAP
1554 @node Other Git documentation
1555 @section Other Git documentation
1559 Official git man pages:
1560 @uref{http://www.kernel.org/pub/software/scm/git/docs/}
1563 More in-depth tutorials: @uref{http://git-scm.com/documentation}
1566 Book about git: @uref{http://progit.org/,Pro Git}