]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/contributor/git-starting.itexi
Merge branch 'lilypond/translation' of ssh://jomand@git.sv.gnu.org/srv/git/lilypond
[lilypond.git] / Documentation / contributor / git-starting.itexi
1 @c -*- coding: us-ascii; mode: texinfo; -*-
2 @node Starting with git
3 @chapter Starting with git
4
5 The goal of this chapter is to provide all the git commands that
6 contributors should know for basic lilypond development.  However,
7 to complete or present in another form the introduction to Git
8 usage in this chapter, it may be a good idea to look at the other
9 Git documentation listed in @ref{Other git documentation}.
10
11 @menu
12 * Getting the source code::     
13 * Updating the source code::    
14 * Sharing your changes::        
15 * Advanced git stuff::          
16 * Git on Windows::
17 * Other git documentation::
18 @end menu
19
20
21 @node Getting the source code
22 @section Getting the source code
23
24 @menu
25 * Git introduction::            
26 * Git user configuration::      
27 * Main source code::            
28 * Documentation translations source code::  
29 * Other branches::              
30 * Other locations for git::     
31 @end menu
32
33 @node Git introduction
34 @subsection Git introduction
35
36 The source code is kept in a Git respository.  This allows us to
37 track changes to files, and for multiple people to work on the
38 same set of files efficiently.
39
40 After downloading the source code, it is important to update the
41 repository by @ref{Updating the source code}.
42
43 @warning{These instructions assume that you are using the
44 command-line version of Git 1.5 or higher.  Windows users should
45 skip to @ref{Git on Windows}.}
46
47
48 @node Git user configuration
49 @subsection Git user configuration
50
51 Some useful cofiguration can be performed automatically; cut and
52 paste the following section:
53
54 @example
55 git config --global color.ui auto
56 @end example
57
58 To configure git to automatically use your name and email address
59 for commits and patches, edit the below lines by changing all the
60 @code{MY...} entries:
61
62 @example
63 git config --global user.name "MYNAME"
64 git config --global user.email MYEMAIL@@EXAMPLE.NET
65 @end example
66
67
68 @node Main source code
69 @subsection Main source code
70
71 To get the main source code and documentation,
72
73 @c WARNING: when updating the commands below, please
74 @c update the other flavors in the two next nodes
75 @c and in Introduction to Git concepts
76 @smallexample
77 mkdir lilypond; cd lilypond
78 git init-db
79 git remote add -f -t master -m master origin git://git.sv.gnu.org/lilypond.git/
80 git checkout -b master origin/master
81 @end smallexample
82
83
84 @node Documentation translations source code
85 @subsection Documentation translations source code
86
87 To translate the documentation,
88
89 @smallexample
90 mkdir lilypond-translation; cd lilypond-translation
91 git init-db
92 git remote add -f -t lilypond/translation -m lilypond/translation origin git://git.sv.gnu.org/lilypond.git/
93 git checkout -b lilypond/translation origin/lilypond/translation
94 @end smallexample
95
96
97 @node Other branches
98 @subsection Other branches
99
100 Most contributors will never need to touch the other branches.  If
101 you wish to do so, you will need more familiarity with git; please
102 see @ref{Other git documentation}.
103
104 @itemize
105
106 @item @code{dev/XYZ}:
107 These branches are for individual developers.  They store code
108 which is not yet stable enough to be added to the @code{master}
109 branch.
110
111 @item @code{stable/XYZ}:
112 The branches are kept for archival reasons.
113
114 @end itemize
115
116 Another item of interest might be the Grand Unified Builder, our
117 cross-platform building tool.  Since it is used by projects as
118 well, it is not stored in our gub repository.  For more info, see
119 @uref{http://lilypond.org/gub}.  The git location is:
120
121 @example
122 http://github.com/janneke/gub
123 @end example
124
125
126 @node Other locations for git
127 @subsection Other locations for git
128
129 If you have difficulty connecting to most of the repositories
130 listed in earlier sections, try:
131
132 @example
133 http://git.sv.gnu.org/r/lilypond.git
134 git://git.sv.gnu.org/lilypond.git
135 ssh://git.sv.gnu.org/srv/git/lilypond.git
136 @end example
137
138 Using HTTP protocol is slowest, so it is not recommended unless both
139 SSH and Git protocols fail, which happens e.g. if you connect to
140 internet through a router that filters out Git and/or SSH connections.
141
142
143
144 @node Updating the source code
145 @section Updating the source code
146
147 @menu
148 * Importance of updating::      
149 * Update command::              
150 * Resolving conflicts::         
151 @end menu
152
153
154 @node Importance of updating
155 @subsection Importance of updating
156
157 In a large project like LilyPond, contributors sometimes edit the same
158 file at the same time.  As long as everybody updates their version of
159 the file with the most recent changes (@emph{pulling}), there are
160 generally no problems with this multiple-person editing.  However,
161 big problems can arise if you do not pull before attempting to
162 commit.  If this occurs, see @ref{Resolving conflicts}.
163
164
165 @node Update command
166 @subsection Updating command
167
168 Whenever you are asked to pull, it means you should update your
169 local copy of the repository with the changes made by others on
170 the remote @code{git.sv.gnu.org} repository:
171
172 @example
173 git pull -r
174 @end example
175
176 @noindent
177 The @code{-r} option is short for @code{--rebase}.  If you don't
178 edit translated documentation and don't want to type @code{-r}
179 every time, add @code{rebase = true} to the master branch in your
180 @file{.git/config}, like so:
181
182 @example
183 [branch "master"]
184         remote = origin
185         merge = refs/heads/master
186         rebase = true
187 @end example
188
189 @warning{translators and documentation editors, if you have
190 changed committishes in the head of translated files using commits
191 you have not yet pushed to @code{git.sv.gnu.org}, please do not
192 rebase.  If you want to avoid wondering whether you should rebase
193 each time you pull, please always use committishes from master
194 and/or lilypond/translation branch on @code{git.sv.gnu.org}, which
195 in particular implies that you must push your changes to
196 documentation except committishes updates (possibly after having
197 rebased), then update the committishes and push them.}
198
199 @c FIXME: when committishes automatic conditional update have been
200 @c tested and documented, append the following to the warning above:
201 @c Note that using update-committishes make target generally touches
202 @c committishes.
203
204
205 @node Resolving conflicts
206 @subsection Resolving conflicts
207
208 Occasionally an update may result in conflicts -- this happens
209 when you and somebody else have modified the same part of the same
210 file and git cannot figure out how to merge the two versions
211 together.  When this happens, you must manually merge the two
212 versions.
213
214 If you need some documentation to understand and resolve conflicts,
215 see paragraphs @emph{How conflicts are presented} and @emph{How to
216 resolve conflicts} in @command{git merge} man page.
217
218 If all else fails, you can follow the instructions in
219 @ref{Reverting all local changes}.  Be aware that this eliminates
220 any changes you have made!
221
222
223 @node Sharing your changes
224 @section Sharing your changes
225
226 @menu
227 * Producing a patch::           
228 * Committing directly::         
229 @end menu
230
231
232 @node Producing a patch
233 @subsection Producing a patch
234
235 Once you have finished editing your files, checked that your changes
236 meet the @ref{Code style}, and/or @ref{Documentation policy}, properly
237 set up your name and email in @ref{Git user configuration}, and
238 checked that the entire thing compiles, you may:
239
240 @example
241 git commit -a
242 git format-patch origin
243 @end example
244
245 The commit should include a brief message describing the change.
246 This consists of a one-line summary describing the change, and
247 if necessary a blank line followed by several lines giving the
248 details:
249
250 @example
251 Did household chores.
252
253 I hung up the wet laundry and then washed the car.  I also
254 vacuumed the floors, rinsed the dirty dishes, fed the cat, and
255 recalibrated the temporal flux machine.
256 @end example
257
258 If the change is to the documentation only then the one-line
259 summary should be prefixed with @qq{Docs: }.
260
261 If you added a file to the source code, you must add it to git
262 with:
263
264 @example
265 git add @var{FILENAME}
266 @end example
267
268 @noindent
269 (and possibly modify the @file{GNUmakefile})
270
271 These commands will produce one or more files named @file{0001-xyz},
272 @file{0002-abc}, etc. in the top directory of the git tree.  Send an
273 email to @email{lilypond-devel@@gnu.org} with these files attached, and
274 a developer will review and apply the patches to the main repository.
275 If your patch is some translation work, you may send it to
276 @email{translations@@lilynet.net} instead.
277
278 To check if you have correctly added any new files, use:
279
280 @example
281 git status
282 @end example
283
284 @noindent
285 If this command lists any @emph{Changed but not updated} files,
286 you should do a @command{git commit}.  If it lists any
287 @emph{Untracked files}, then you should do a @command{git add}.
288
289
290 @node Committing directly
291 @subsection Committing directly
292
293 Most contributors do not have permission to commit directly.  If you do,
294 make sure you have set up your name and email in @ref{Git user
295 configuration}, then edit @file{.git/config}: change the line
296
297 @example
298 url = git://git.sv.gnu.org/lilypond.git/
299 @end example
300
301 @noindent
302 into
303
304 @example
305 url = ssh://@var{user}@@git.sv.gnu.org/srv/git/lilypond.git
306 @end example
307
308 @noindent
309 where @var{user} is your login name on Savannah.
310
311 If you have not already done so, you should generate and upload a
312 SSH key: open @uref{https://savannah.gnu.org/my/} in your browser,
313 go to @q{Account Configuration}, then to something like
314 @q{Edit SSH Keys}, and follow the instructions on that page.
315
316 You may then:
317
318 @example
319 git push origin
320 @end example
321
322 Note that recent versions of Git (Git 1.6.3 or later) will issue a
323 big warning if the above command is used.  The simplest solution
324 is to add a new section to @file{.git/config} that looks like
325 this:
326
327 @example
328 [push]
329         default = matching
330 @end example
331
332 @noindent
333 Then @code{git push origin} will work as before.  For more
334 details, consult the @code{git push} man page.
335
336
337 @node Advanced git stuff
338 @section Advanced git stuff
339
340 @warning{This section is not necessary for normal contributors;
341 these commands are presented for information for people interested
342 in learning more about git.}
343
344
345 It is possible to work with several branches on the same local Git
346 repository; this is especially useful for translators who may have to
347 deal with both @code{lilypond/translation} and a stable branch,
348 e.g. @code{stable/2.12}.
349
350 Some Git commands are introduced first, then a workflow with several
351 Git branches of LilyPond source code is presented.
352
353 @menu
354 * Introduction to Git concepts::  
355 * Git commands for managing several branches::  
356 * Working on LilyPond sources with several branches::  
357 * Git log::                     
358 * Applying git patches::        
359 * Reverting all local changes::  
360 @end menu
361
362
363 @node Introduction to Git concepts
364 @subsection Introduction to Git concepts
365
366 A bit of Git vocabulary will be explained below.  The following is
367 just introduction material; for better understanding of Git concepts,
368 you are invited to read further documentation, especially Git
369 Community Book at @uref{http://book.git-scm.com/}.
370
371 The @code{git pull origin} command above is just a shortcut for this
372 command:
373
374 @example
375 git pull git://git.sv.gnu.org/lilypond.git/ @var{branch}:origin/@var{branch}
376 @end example
377
378 @noindent
379 where @code{@var{branch}} is typically @code{master}, @code{web} or
380 @code{lilypond/translation}; if you do not know or remember, see
381 @ref{Getting the source code} to remember which commands you issued or
382 which source code you wanted to get.
383
384 A @emph{commit} is a set of changes made to the sources; it also
385 includes the committish of the parent commit, the name and e-mail of
386 the @emph{author} (the person who wrote the changes), the name and
387 e-mail of the @emph{committer} (the person who brings these changes
388 into the Git repository), and a commit message.
389
390 A @emph{committish} is the SHA1 checksum of a commit, a number made of
391 40 hexadecimal digits, which acts as the internal unique identifier
392 for this commit.  To refer to a particular revision, don't use vague
393 references like the (approximative) date, simply copy and paste the
394 committish.
395
396 A @emph{branch} is nothing more than a pointer to a particular commit,
397 which is called the @emph{head} of the branch; when referring to a
398 branch, one often acutally thinks about its head and the ancestor
399 commits of the head.
400
401 Now we will explain the two last commands you used to get the source
402 code from Git -- see @ref{Getting the source code}.
403
404 @example
405 git remote add -f -t @var{branch} -m @var{branch} origin git://git.sv.gnu.org/lilypond.git/
406 git checkout -b @var{branch} origin/@var{branch}
407 @end example
408
409 The @command{git remote} has created a branch called
410 @code{origin/@var{branch}} in your local Git repository.  As this
411 branch is a copy of the remote branch web from git.sv.gnu.org LilyPond
412 repository, it is called a @emph{remote branch}, and is meant to track
413 the changes on the branch from git.sv.gnu.org: it will be updated
414 every time you run @command{git pull origin} or @command{git fetch
415 origin}.
416
417 The @command{git checkout} command has created a branch named
418 @code{@var{branch}}.  At the beginning, this branch is identical to
419 @code{origin/@var{branch}}, but it will differ as soon as you make
420 changes, e.g. adding newly translated pages or editing some
421 documentation or code source file.  Whenever you pull, you merge the
422 changes from @code{origin/@var{branch}} and @code{@var{branch}} since
423 the last pulling.  If you do not have push (i.e. @qq{write}) access on
424 git.sv.gnu.org, your @code{@var{branch}} will always differ from
425 @code{origin/@var{branch}}.  In this case, remember that other people
426 working like you with the remote branch @code{@var{branch}} of
427 git://git.sv.gnu.org/lilypond.git/ (called @code{origin/@var{branch}}
428 on your local repository) know nothing about your own
429 @code{@var{branch}}: this means that whenever you use a committish or
430 make a patch, others expect you to take the latest commit of
431 @code{origin/@var{branch}} as a reference.
432
433 Finally, please remember to read the man page of every Git command you
434 will find in this manual in case you want to discover alternate
435 methods or just understand how it works.
436
437
438 @node Git commands for managing several branches
439 @subsection Git commands for managing several branches
440
441 @subsubheading Listing branches and remotes
442
443 You can get the exact path or URL of all remotes with
444 running
445
446 @example
447 git remote -v
448 @end example
449
450 To list Git branches on your local repositories, run
451
452 @example
453 git branch     # list local branches only
454 git branch -r  # list remote branches
455 git branch -a  # list all branches
456 @end example
457
458
459 @subsubheading Checking out branches
460
461 To know the currently checked out branch, i.e. the branch whose source
462 files are present in your working tree, read the first line of the
463 output of
464
465 @example
466 git status
467 @end example
468
469 @noindent
470 The currently checked out branch is also marked with an asterisk in
471 the output of @command{git branch}.
472
473 You can check out another branch @code{@var{other_branch}}, i.e. check
474 out @code{@var{other_branch}} to the working tree, by running
475
476 @example
477 git checkout @var{other_branch}
478 @end example
479
480 Note that it is possible to check out another branch while having
481 uncommitted changes, but it is not recommended unless you know what
482 you are doing; it is recommended to run @command{git status} to check
483 this kind of issue before checking out another branch.
484
485
486 @subsubheading Merging branches
487
488 To merge branch @code{@var{foo}} into branch @code{@var{bar}}, i.e. to
489 @qq{add} all changes made in branch @code{@var{foo}} to branch
490 @code{@var{bar}}, run
491
492 @example
493 git checkout @var{bar}
494 git merge @var{foo}
495 @end example
496
497 If any conflict happens, see @ref{Resolving conflicts}.
498
499 There are common usage cases for merging: as a translator, you will
500 often want to merge @code{master} into @code{lilypond/translation}; on
501 the other hand, the Translations meister wants to merge
502 @code{lilypond/translation} into @code{master} whenever he has checked
503 that @code{lilypond/translation} builds successfully.
504
505
506 @node Working on LilyPond sources with several branches
507 @subsection Working on LilyPond sources with several branches
508
509 @subsubheading Fetching new branches from git.sv.gnu.org
510
511 To fetch and check out a new branch named @code{@var{branch}} on
512 git.sv.gnu.org, run from top of the Git repository
513
514 @example
515 git config --add remote.origin.fetch +refs/heads/@var{branch}:refs/remotes/origin/@var{branch}
516 git checkout --track -b @var{branch} origin/@var{branch}
517 @end example
518
519 After this, you can pull @code{@var{branch}} from git.sv.gnu.org with
520
521 @example
522 git pull origin
523 @end example
524
525 Note that this command generally fetches all branches you added with
526 @command{git remote add} (when you initialized the repository) or
527 @command{git config --add}, i.e. it updates all remote branches from
528 remote @code{origin}, then it merges the remote branch tracked by
529 current branch into current branch.  For example, if your current
530 branch is @code{master} --- which is the case if you got the sources
531 with the commands described in @ref{Main source code} and did not
532 issue any @command{git checkout} command --- @code{origin/master} will
533 be merged into @code{master}.
534
535
536 @subsubheading Local clones, or having several working trees
537
538 If you play with several Git branches, e.g. @code{master},
539 @code{lilypond/translation}, @code{stable/2.12}), you may want to have
540 one source and build tree for each branch; this is possible with
541 subdirectories of your local Git repository, used as local cloned
542 subrepositories.  To create a local clone for the branch named
543 @code{@var{branch}}, run
544
545 @example
546 git checkout @var{branch}
547 git clone -l -s -n . @var{subdir}
548 cd @var{subdir}
549 git reset --hard
550 @end example
551
552 Note that @code{@var{subdir}} must be a directory name which does not
553 already exist.  In @code{@var{subdir}}, you can use all Git commands
554 to browse revisions history, commit and uncommit changes; to update
555 the cloned subrepository with changes made on the main repository, cd
556 into @code{@var{subdir}} and run @command{git pull}; to send changes
557 made on the subrepository back to the main repository, run
558 @command{git push} from @code{@var{subdir}}.  Note that only one
559 branch (the currently checked out branch) is created in the
560 subrepository by default; it is possible to have several branches in a
561 subrepository and do usual operations (checkout, merge, create,
562 delete...) on these branches, but this possibility is not detailed
563 here.
564
565 When you push @code{@var{branch}} from @code{@var{subdir}} to the main
566 repository, and @code{@var{branch}} is checked out in the main
567 repository, you must save uncommitted changes (see @command{git
568 stash}) and do @command{git reset --hard} in the main repository in
569 order to apply pushed changes in the working tree of the main
570 repository.
571
572
573 @node Git log
574 @subsection Git log
575
576 The commands above don't only bring you the latest version of the
577 sources, but also the full history of revisions (revisons, also
578 called commits, are changes made to the sources), stored in the
579 .git directory.  You can browse this history with
580
581 @example
582 git log     # only shows the logs (author, committish and commit message)
583 git log -p  # also shows diffs
584 gitk        # shows history graphically
585 @end example
586
587 @warning{The @code{gitk} command may require a separate @code{gitk} package,
588 available in the appropriate distribution's repositories.}
589
590
591 @node Applying git patches
592 @subsection Applying git patches
593
594 Well-formed git patches created with @code{git format-patch}
595 should be committed with the following command:
596
597 @example
598 git am @var{patch}
599 @end example
600
601 Patches created without @code{git format-patch} can be applied in
602 two steps.  The first step is to apply the patch to the working
603 tree:
604
605 @example
606 git apply @var{patch}
607 @end example
608
609 @noindent
610 The second step is to commit the changes and give credit to the
611 author of the patch.  This can be done with the following command:
612
613 @example
614 git commit -a --author="First Last <user@@example.net>"
615 @end example
616
617
618 @node Reverting all local changes
619 @subsection Reverting all local changes
620
621 Sometimes git will become hopelessly confused, and you just want
622 to get back to a known, stable state.  This command destroys any
623 local changes you have made, but at least you get back to the
624 current online version:
625
626 @example
627 git reset --hard origin/master
628 @end example
629
630
631 @node Git on Windows
632 @section Git on Windows
633
634 @c Some of this may duplicate stuff in other sections
635 @c But it is probably best for windows users to have it all together
636 @c If necessary, clear this up later  -td
637
638 @subsection Background to nomenclature
639
640 Git is a system for tracking the changes made to source files by
641 a distributed set of editors.  It is designed to work without a
642 master repository, but we have chosen to have a master respository
643 for LilyPond files.  Editors hold a local copy of the master
644 repository together with any changes they have made locally.  Local
645 changes are held in a local @q{branch}, of which there may be
646 several, but these instructions assume you are using just one.  The
647 files visible in the local repository always correspond to those
648 on the currently @q{checked out} local branch.
649
650 Files are edited on a local branch, and in that state the
651 changes are said to be @q{unstaged}.  When editing is complete, the
652 changes are moved to being @q{staged for commit}, and finally the
653 changes are @q{committed} to the local branch.  Once committed, the
654 changes (called a @q{commit}) are given a unique 40-digit hexadecimal
655 reference number called the @q{Committish} or @q{SHA1 ID} which
656 identifies the commit to Git.  Such committed changes can be sent to
657 the master repository by @q{pushing} them (if you have write
658 permission) or by sending them by email to someone who has, either
659 as a complete file or as a @q{diff} or @q{patch} (which send just
660 the differences from the master repository).
661
662 @subsection Installing git
663
664 Obtain Git from
665 @uref{http://code.google.com/p/msysgit/downloads/list}
666 (note, not msysGit, which is for Git developers and not PortableGit,
667 which is not a full git installation) and
668 install it.
669
670 Note that most users will not need to install SSH.  That is not
671 required until you have been granted direct push permissions to
672 the master git repository.
673
674 Start Git by clicking on the desktop icon.
675 This will bring up a command line bash shell.  This may be
676 unfamiliar to Windows users.  If so, follow these
677 instructions carefully.  Commands are entered at a $ prompt
678 and are terminated by keying a newline.
679
680 @subsection Initialising Git
681
682 Decide where you wish to place your local Git repository,
683 creating the folders in Windows as necessary.  Here we
684 call the folder to contain the repository @code{[path]/Git}, but 
685 if you intend using Git for other projects a directory name like
686 @code{lilypond-git} might be better.  You will need to have space
687 for around 100Mbytes.
688
689 Start the Git bash shell by clicking on the desk-top icon installed
690 with Git and type
691
692 @example
693 cd [path]/Git
694 @end example
695
696 to position the shell at your new Git repository.
697
698 Note: if [path] contains folders with names containing
699 spaces use
700
701 @example
702 cd "[path]/Git"
703 @end example
704
705 Then type
706
707 @example
708 git init
709 @end example
710
711 to initialize your Git repository.
712
713 Then type (all on one line; the shell will wrap automatically)
714
715 @example
716 git remote add -f -t master origin git://git.sv.gnu.org/lilypond.git
717 @end example
718
719 to download the lilypond master files.
720
721 @warning{Be patient!  Even on a broadband connection this can take
722 10 minutes or more.  Wait for lots of [new tag] messages
723 and the $ prompt.}
724
725 We now need to generate a local copy of the downloaded files
726 in a new local branch.  Your local branch needs to have a
727 name.  It is usual to call it @q{master} and we shall do that
728 here.
729
730 To do this, type
731
732 @example
733 git checkout -b master origin/master
734 @end example
735
736 This creates a second branch called @q{master}.  You will see
737 two warnings (ignore these), and a message advising you that
738 your local branch @q{master} has been set up to track the remote
739 branch.  You now have two branches, a local branch called
740 @q{master}, and a tracking branch called @q{origin/master},
741 which is a shortened form of @q{remotes/origin/master}.
742
743 Return to Windows Explorer and look in your Git repository.  You
744 should see lots of folders.  For example, the LilyPond documentation
745 can be found in [path]/Git/Documentation/.
746
747 The Git bash shell is terminated by typing @code{exit} or by
748 clicking on the usual Windows close-window widget.
749
750 @subsection Git GUI
751
752 Almost all subsequent work will use the Git Graphical User
753 Interface, which avoids having to type command line
754 commands. To start Git GUI first start the Git bash shell by
755 clicking on the desktop icon, and type
756
757 @example
758 cd [path]/Git
759 git gui
760 @end example
761
762 The Git GUI will open in a new window.  It contains four panels
763 and 7 pull-down menus.  At this stage do not use any of the
764 commands under Branch, Commit, Merge or Remote.  These will
765 be explained later.
766
767 The top panel on the left contains the names of files which
768 you are in the process of editing (Unstaged Changes), and the
769 lower panel on the left contains the names of
770 files you have finished editing and have staged ready for
771 committing (Staged Changes).  At present, these panels will
772 be empty as you have not yet made any changes to any file.
773 After a file has been edited and saved the top panel on the right
774 will display the differences between the edited file selected
775 in one of the panels on the left and the last version committed
776 on the current branch.
777
778 The panel at bottom right is used to enter a descriptive
779 message about the change before committing it.
780
781 The Git GUI is terminated by entering CNTL-Q while it is the
782 active window or by clicking on the usual Windows close-window
783 widget.
784
785 @subsection Personalising your local git repository
786
787 Open the Git GUI, click on
788
789 @example
790 Edit -> Options
791 @end example
792
793 and enter your name and email address in the
794 left-hand (Git Repository) panel.  Leave everything
795 else unchanged and save it.
796
797 Note that Windows users must leave the default setting for line
798 endings unchanged.  All files in a git repository must have lines
799 terminated by just a LF, as this is required for Merge to work, but
800 Windows files are terminated by CRLF by default.  The git default
801 setting causes the line endings of files in a Windows git repository
802 to be flipped automatically between LF and CRLF as required.  This
803 enables files to be edited by any Windows editor without causing
804 problems in the git repository.
805
806 @subsection Checking out a branch
807
808 At this stage you have two branches in your local repository,
809 both identical.  To see them click on
810
811 @example
812 Branch -> Checkout
813 @end example
814
815 You should have one local branch called @q{master} and one
816 tracking branch called @q{origin/master}.  The latter is your
817 local copy of the @q{remotes/origin/master} branch in the master
818 LilyPond repository.  The local @q{master} branch is where you
819 will make your local changes.
820
821 When a particular branch is selected, i.e., checked out, the
822 files visible in your repository are changed to reflect the
823 state of the files on that branch.
824
825 @subsection Updating files from @q{remote/origin/master}
826
827 Before starting the editing of a file, ensure your local repository
828 contains the latest version of the files in the remote repository
829 by first clicking
830
831 @example
832 Remote -> Fetch from -> origin
833 @end example
834
835 @noindent
836 in the Git GUI.
837
838 This will place the latest version of every file, including all the
839 changes made by others, into the @q{origin/master} branch of the
840 tracking branches in your git repository.  You can see these files
841 by checking out this branch, but you must @emph{never} edit any
842 files while this branch is checked out.  Check out your local
843 @q{master} branch again.
844
845 You then need to merge these fetched files into your local @q{master}
846 branch by clicking on
847
848 @example
849 Merge -> Local Merge
850 @end example
851
852 @noindent
853 and if necessary select the local @q{master} branch.
854
855 Note that a merge cannot be completed if you have made any local
856 changes which have not yet been committed.
857
858 This merge will update all the files in the @q{master} branch to
859 reflect the current state of the @q{origin/master} branch.  If any
860 of the changes conflict with changes you have made yourself recently
861 you will be notified of the conflict (see below).
862
863 @subsection Editing files
864
865 First ensure your @q{master} branch is checked out, then
866 simply edit the files in your local Git repository with your
867 favourite editor and save them back there.  If any file contains
868 non-ASCII characters ensure you save it in UTF-8 format.  Git will
869 detect any changes whenever you restart Git GUI and the file names
870 will then be listed in the Unstaged Changes panel.
871 Or you can click the Rescan button to refresh the panel
872 contents at any time.  You may break off and resume editing any
873 time.
874
875 The changes you have made may be displayed in diff form in the top
876 right-hand panel of Git GUI by clicking on the file name shown in
877 one of the left panels.
878
879 When your editing is complete, move the files from being
880 Unstaged to Staged by clicking the document symbol to
881 the left of each name.  If you change your mind it can
882 be moved back by clicking on the ticked box to the
883 left of the name.
884
885 Finally the changes you have made may be committed to
886 your @q{master} branch by entering a brief message in
887 the Commit Message box and clicking the Commit button.
888
889 If you wish to amend your changes after a commit has been
890 made, the original version and the changes you made in that
891 commit may be recovered by selecting
892
893 @example
894 Commit -> Amend Last Commit
895 @end example
896
897 @noindent
898 or by checking the Amend Last Commit radio button at bottom right.
899 This will return the changes to the Staged state, so further
900 editing made be carried out within that commit.  This must only be
901 done @emph{before} the changes have been Pushed or sent to your
902 mentor for Pushing - after that it is too late and corrections
903 have to be made as a separate commit.
904
905
906 @subsection Sending changes to @q{remotes/origin/master}
907
908 If you do not have write access to @q{remotes/origin/master} you
909 will need to send your changes by email to someone who does.
910
911 First you need to create a diff or patch file containing
912 your changes.  To create this, the file must first be
913 committed.  Then terminate the Git GUI.  In the
914 git bash shell first cd to your Git repository with
915
916 @example
917 cd [path]/Git
918 @end example
919
920 if necessary, then produce the patch with
921
922 @example
923 git format-patch origin
924 @end example
925
926 This will create a patch file for all the locally committed files
927 which differ from @q{origin/master}.  The patch file can be found
928 in [path]/Git and will have a name formed from the commit
929 message.
930
931 @subsection Resolving merge conflicts
932
933 As soon as you have committed a changed file your local @q{master}
934 branch has diverged from @q{origin/master}, and will
935 remain diverged until your changes have been committed
936 in @q{remotes/origin/master} and Fetched back into your
937 @q{origin/master} branch.  Similarly, if a new commit has been made
938 to @q{remotes/origin/master} by someone else and Fetched, your
939 local @q{master} branch is divergent.  You can detect a divergent
940 branch by clicking on
941
942 @example
943 Repository -> Visualise all branch history
944 @end example
945
946 This opens up a very useful new window called @q{gitk}.
947 Use this to browse all the commits made by yourself and others.
948
949 If the diagram at top left of the resulting window
950 does not show your @q{master} tag on the same node as
951 the @q{remotes/origin/master} tag your branch has diverged from
952 @q{origin/master}.  This is quite normal if files you have modified
953 yourself have not yet been Pushed to @q{remotes/origin/master} and
954 Fetched, or if files modified and committed by others have been
955 Fetched since you last Merged @q{origin/master} into your local
956 @q{master} branch.
957
958 If a file being merged from @q{origin/master} differs from
959 one you have modified in a way that cannot be resolved
960 automatically by git, Merge will report a Conflict
961 which you must resolve by editing the file to create the
962 version you wish to keep.
963
964 This could happen if the person updating @q{remotes/origin/master}
965 for you has added some changes of his own before
966 committing your changes to @q{remotes/origin/master}, or if someone
967 else has changed the same file since you last
968 fetched the file from @q{remotes/origin/master}.
969
970 Open the file in your editor and look for sections which
971 are delimited with ...
972
973 [to be completed when I next have a merge conflict to be
974 sure I give the right instructions  -td]
975
976
977 @subsection Other actions
978
979 The instructions above describe the simplest way of using
980 git on Windows.  Other git facilities which may usefully
981 supplement these include
982
983 @itemize
984
985 @item Using multiple local branches (Create, Rename, Delete)
986 @item Resetting branches
987 @item Cherry-picking commits
988 @item Pushing commits to @w{remote/origin/master}
989 @item Using gitk to review history
990
991 @end itemize
992
993 Once familiarity with using git on Windows has been gained the
994 standard git manuals can be used to learn about these.
995
996
997 @node Other git documentation
998 @section Other git documentation
999
1000 @itemize
1001
1002 @item
1003 Official git man pages: @uref{http://www.kernel.org/pub/software/scm/git/docs/}
1004
1005 @item
1006 More in-depth tutorials: @uref{http://git-scm.com/documentation}
1007
1008 @item
1009 Book about git: @uref{http://progit.org/,Pro Git}
1010
1011 @end itemize
1012