1 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.1//EN"
2 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3 <html xmlns=
"http://www.w3.org/1999/xhtml" xml:
lang=
"en">
5 <meta http-equiv=
"Content-Type" content=
"text/html; charset=UTF-8" />
6 <meta name=
"generator" content=
"AsciiDoc 8.4.5" />
7 <title>Everyday GIT With
20 Commands Or So
</title>
8 <style type=
"text/css">
10 p
, li
, dt
, dd
, div
, pre
, h1
, h2
, h3
, h4
, h5
, h6
{
12 border: 1px solid red;
17 margin: 1em 5% 1em 5%;
22 text-decoration: underline
;
42 h1
, h2
, h3
, h4
, h5
, h6
{
44 font-family: sans-serif
;
51 border-bottom: 2px solid silver
;
69 border: 1px solid silver
;
88 font-family: sans-serif
;
94 span#revnumber
, span#revdate
, span#revremark
{
95 font-family: sans-serif
;
99 font-family: sans-serif
;
101 border-top: 2px solid silver
;
107 padding-bottom: 0.5em;
111 padding-bottom: 0.5em;
116 margin-bottom: 1.5em;
118 div
.tableblock
, div
.imageblock
, div
.exampleblock
, div
.verseblock
,
119 div
.quoteblock
, div
.literalblock
, div
.listingblock
, div
.sidebarblock
,
120 div
.admonitionblock
{
122 margin-bottom: 1.5em;
124 div
.admonitionblock
{
126 margin-bottom: 2.5em;
129 div
.content
{ /* Block element content. */
133 /* Block element titles. */
134 div
.title
, caption
.title
{
136 font-family: sans-serif
;
140 margin-bottom: 0.5em;
146 td div
.title:first-child
{
149 div
.content div
.title:first-child
{
152 div
.content
+ div
.title
{
156 div
.sidebarblock
> div
.content
{
158 border: 1px solid silver
;
162 div
.listingblock
> div
.content
{
163 border: 1px solid silver
;
172 div
.quoteblock
> div
.attribution
{
181 div
.verseblock
> div
.content
{
184 div
.verseblock
> div
.attribution
{
188 /* DEPRECATED: Pre version 8.2.7 verse style literal block. */
189 div
.verseblock
+ div
.attribution
{
193 div
.admonitionblock
.icon
{
197 text-decoration: underline
;
199 padding-right: 0.5em;
201 div
.admonitionblock td
.content
{
203 border-left: 2px solid silver
;
206 div
.exampleblock
> div
.content
{
207 border-left: 2px solid silver
;
211 div
.imageblock div
.content
{ padding-left: 0; }
212 span
.image img
{ border-style: none
; }
213 a
.image:visited
{ color: white
; }
217 margin-bottom: 0.8em;
230 list-style-position: outside
;
233 list-style-type: decimal
;
236 list-style-type: lower-alpha
;
239 list-style-type: upper-alpha
;
242 list-style-type: lower-roman
;
245 list-style-type: upper-roman
;
248 div
.compact ul
, div
.compact ol
,
249 div
.compact p
, div
.compact p
,
250 div
.compact div
, div
.compact div
{
252 margin-bottom: 0.1em;
255 div
.tableblock
> table
{
256 border: 3px solid
#527bbd;
259 font-family: sans-serif
;
271 /* Because the table frame attribute is overriden by CSS in most browsers. */
272 div
.tableblock
> table
[frame
="void"] {
275 div
.tableblock
> table
[frame
="hsides"] {
276 border-left-style: none
;
277 border-right-style: none
;
279 div
.tableblock
> table
[frame
="vsides"] {
280 border-top-style: none
;
281 border-bottom-style: none
;
287 margin-bottom: 0.8em;
290 padding-bottom: 15px;
292 dt
.hdlist1
.strong
, td
.hdlist1
.strong
{
298 padding-right: 0.8em;
304 div
.hdlist
.compact tr
{
314 div#footer-badges
{ display: none
; }
319 font-family: sans-serif
;
323 margin-bottom: 0.1em;
326 div
.toclevel1
, div
.toclevel2
, div
.toclevel3
, div
.toclevel4
{
342 /* Workarounds for IE6's broken and incomplete CSS2. */
344 div
.sidebar-content
{
346 border: 1px solid silver
;
349 div
.sidebar-title
, div
.image-title
{
351 font-family: sans-serif
;
354 margin-bottom: 0.5em;
357 div
.listingblock div
.content
{
358 border: 1px solid silver
;
363 div
.quoteblock-attribution
{
368 div
.verseblock-content
{
371 div
.verseblock-attribution
{
376 div
.exampleblock-content
{
377 border-left: 2px solid silver
;
381 /* IE6 sets dynamically generated links as visited. */
382 div#toc
a:visited
{ color: blue
; }
387 <h1>Everyday GIT With
20 Commands Or So
</h1>
390 <div class=
"sectionbody">
391 <div class=
"paragraph"><p><a href=
"#Individual Developer (Standalone)">[Individual Developer (Standalone)]
</a> commands are essential for
392 anybody who makes a commit, even for somebody who works alone.
</p></div>
393 <div class=
"paragraph"><p>If you work with other people, you will need commands listed in
394 the
<a href=
"#Individual Developer (Participant)">[Individual Developer (Participant)]
</a> section as well.
</p></div>
395 <div class=
"paragraph"><p>People who play the
<a href=
"#Integrator">[Integrator]
</a> role need to learn some more
396 commands in addition to the above.
</p></div>
397 <div class=
"paragraph"><p><a href=
"#Repository Administration">[Repository Administration]
</a> commands are for system
398 administrators who are responsible for the care and feeding
399 of git repositories.
</p></div>
402 <h2 id=
"_individual_developer_standalone_a_id_individual_developer_standalone_a">Individual Developer (Standalone)
<a id=
"Individual Developer (Standalone)"></a></h2>
403 <div class=
"sectionbody">
404 <div class=
"paragraph"><p>A standalone individual developer does not exchange patches with
405 other people, and works alone in a single repository, using the
406 following commands.
</p></div>
407 <div class=
"ulist"><ul>
410 <a href=
"git-init.html">git-init(
1)
</a> to create a new repository.
415 <a href=
"git-show-branch.html">git-show-branch(
1)
</a> to see where you are.
420 <a href=
"git-log.html">git-log(
1)
</a> to see what happened.
425 <a href=
"git-checkout.html">git-checkout(
1)
</a> and
<a href=
"git-branch.html">git-branch(
1)
</a> to switch
431 <a href=
"git-add.html">git-add(
1)
</a> to manage the index file.
436 <a href=
"git-diff.html">git-diff(
1)
</a> and
<a href=
"git-status.html">git-status(
1)
</a> to see what
437 you are in the middle of doing.
442 <a href=
"git-commit.html">git-commit(
1)
</a> to advance the current branch.
447 <a href=
"git-reset.html">git-reset(
1)
</a> and
<a href=
"git-checkout.html">git-checkout(
1)
</a> (with
448 pathname parameters) to undo changes.
453 <a href=
"git-merge.html">git-merge(
1)
</a> to merge between local branches.
458 <a href=
"git-rebase.html">git-rebase(
1)
</a> to maintain topic branches.
463 <a href=
"git-tag.html">git-tag(
1)
</a> to mark known point.
467 <h3 id=
"_examples">Examples
</h3><div style=
"clear:left"></div>
468 <div class=
"dlist"><dl>
470 Use a tarball as a starting point for a new repository.
473 <div class=
"listingblock">
474 <div class=
"content">
475 <pre><tt>$ tar zxf frotz.tar.gz
478 $ git add .
<b><1></b>
479 $ git commit -m
"import of frotz source tree."
480 $ git tag v2.43
<b><2></b></tt></pre>
482 <div class=
"colist arabic"><ol>
485 add everything under the current directory.
490 make a lightweight, unannotated tag.
496 Create a topic branch and develop.
499 <div class=
"listingblock">
500 <div class=
"content">
501 <pre><tt>$ git checkout -b alsa-audio
<b><1></b>
503 $ git checkout -- curses/ux_audio_oss.c
<b><2></b>
504 $ git add curses/ux_audio_alsa.c
<b><3></b>
506 $ git diff HEAD
<b><4></b>
507 $ git commit -a -s
<b><5></b>
509 $ git reset --soft HEAD^
<b><6></b>
511 $ git diff ORIG_HEAD
<b><7></b>
512 $ git commit -a -c ORIG_HEAD
<b><8></b>
513 $ git checkout master
<b><9></b>
514 $ git merge alsa-audio
<b><10></b>
515 $ git log --since='
3 days ago'
<b><11></b>
516 $ git log v2.43.. curses/
<b><12></b></tt></pre>
518 <div class=
"colist arabic"><ol>
521 create a new topic branch.
526 revert your botched changes in
<tt>curses/ux_audio_oss.c
</tt>.
531 you need to tell git if you added a new file; removal and
532 modification will be caught if you do
<tt>git commit -a
</tt> later.
537 to see what changes you are committing.
542 commit everything as you have tested, with your sign-off.
547 take the last commit back, keeping what is in the working tree.
552 look at the changes since the premature commit we took back.
557 redo the commit undone in the previous step, using the message
558 you originally wrote.
563 switch to the master branch.
568 merge a topic branch into your master branch.
573 review commit logs; other forms to limit output can be
574 combined and include
<tt>--max-count=
10</tt> (show
10 commits),
575 <tt>--until=
2005-
12-
10</tt>, etc.
580 view only the changes that touch what
’s in
<tt>curses/
</tt>
581 directory, since
<tt>v2.43
</tt> tag.
588 <h2 id=
"_individual_developer_participant_a_id_individual_developer_participant_a">Individual Developer (Participant)
<a id=
"Individual Developer (Participant)"></a></h2>
589 <div class=
"sectionbody">
590 <div class=
"paragraph"><p>A developer working as a participant in a group project needs to
591 learn how to communicate with others, and uses these commands in
592 addition to the ones needed by a standalone developer.
</p></div>
593 <div class=
"ulist"><ul>
596 <a href=
"git-clone.html">git-clone(
1)
</a> from the upstream to prime your local
602 <a href=
"git-pull.html">git-pull(
1)
</a> and
<a href=
"git-fetch.html">git-fetch(
1)
</a> from
"origin"
603 to keep up-to-date with the upstream.
608 <a href=
"git-push.html">git-push(
1)
</a> to shared repository, if you adopt CVS
609 style shared repository workflow.
614 <a href=
"git-format-patch.html">git-format-patch(
1)
</a> to prepare e-mail submission, if
615 you adopt Linux kernel-style public forum workflow.
619 <h3 id=
"_examples_2">Examples
</h3><div style=
"clear:left"></div>
620 <div class=
"dlist"><dl>
622 Clone the upstream and work on it. Feed changes to upstream.
625 <div class=
"listingblock">
626 <div class=
"content">
627 <pre><tt>$ git clone git://git.kernel.org/pub/scm/.../torvalds/linux-
2.6 my2.6
629 $ edit/compile/test; git commit -a -s
<b><1></b>
630 $ git format-patch origin
<b><2></b>
631 $ git pull
<b><3></b>
632 $ git log -p ORIG_HEAD.. arch/i386 include/asm-i386
<b><4></b>
633 $ git pull git://git.kernel.org/pub/.../jgarzik/libata-dev.git ALL
<b><5></b>
634 $ git reset --hard ORIG_HEAD
<b><6></b>
635 $ git gc
<b><7></b>
636 $ git fetch --tags
<b><8></b></tt></pre>
638 <div class=
"colist arabic"><ol>
646 extract patches from your branch for e-mail submission.
651 <tt>git pull
</tt> fetches from
<tt>origin
</tt> by default and merges into the
657 immediately after pulling, look at the changes done upstream
658 since last time we checked, only in the
659 area we are interested in.
664 fetch from a specific branch from a specific repository and merge.
674 garbage collect leftover objects from reverted pull.
679 from time to time, obtain official tags from the
<tt>origin
</tt>
680 and store them under
<tt>.git/refs/tags/
</tt>.
686 Push into another repository.
689 <div class=
"listingblock">
690 <div class=
"content">
691 <pre><tt>satellite$ git clone mothership:frotz frotz
<b><1></b>
693 satellite$ git config --get-regexp '^(remote|branch)\.'
<b><2></b>
694 remote.origin.url mothership:frotz
695 remote.origin.fetch refs/heads/*:refs/remotes/origin/*
696 branch.master.remote origin
697 branch.master.merge refs/heads/master
698 satellite$ git config remote.origin.push \
699 master:refs/remotes/satellite/master
<b><3></b>
700 satellite$ edit/compile/test/commit
701 satellite$ git push origin
<b><4></b>
704 mothership$ git checkout master
705 mothership$ git merge satellite/master
<b><5></b></tt></pre>
707 <div class=
"colist arabic"><ol>
710 mothership machine has a frotz repository under your home
711 directory; clone from it to start a repository on the satellite
717 clone sets these configuration variables by default.
718 It arranges
<tt>git pull
</tt> to fetch and store the branches of mothership
719 machine to local
<tt>remotes/origin/*
</tt> remote-tracking branches.
724 arrange
<tt>git push
</tt> to push local
<tt>master
</tt> branch to
725 <tt>remotes/satellite/master
</tt> branch of the mothership machine.
730 push will stash our work away on
<tt>remotes/satellite/master
</tt>
731 remote-tracking branch on the mothership machine. You could use this
737 on mothership machine, merge the work done on the satellite
738 machine into the master branch.
744 Branch off of a specific tag.
747 <div class=
"listingblock">
748 <div class=
"content">
749 <pre><tt>$ git checkout -b private2.6
.14 v2.6
.14 <b><1></b>
750 $ edit/compile/test; git commit -a
751 $ git checkout master
752 $ git format-patch -k -m --stdout v2.6
.14..private2.6
.14 |
753 git am -
3 -k
<b><2></b></tt></pre>
755 <div class=
"colist arabic"><ol>
758 create a private branch based on a well known (but somewhat behind)
764 forward port all changes in
<tt>private2.6
.14</tt> branch to
<tt>master
</tt> branch
765 without a formal
"merging".
772 <h2 id=
"_integrator_a_id_integrator_a">Integrator
<a id=
"Integrator"></a></h2>
773 <div class=
"sectionbody">
774 <div class=
"paragraph"><p>A fairly central person acting as the integrator in a group
775 project receives changes made by others, reviews and integrates
776 them and publishes the result for others to use, using these
777 commands in addition to the ones needed by participants.
</p></div>
778 <div class=
"ulist"><ul>
781 <a href=
"git-am.html">git-am(
1)
</a> to apply patches e-mailed in from your
787 <a href=
"git-pull.html">git-pull(
1)
</a> to merge from your trusted lieutenants.
792 <a href=
"git-format-patch.html">git-format-patch(
1)
</a> to prepare and send suggested
793 alternative to contributors.
798 <a href=
"git-revert.html">git-revert(
1)
</a> to undo botched commits.
803 <a href=
"git-push.html">git-push(
1)
</a> to publish the bleeding edge.
807 <h3 id=
"_examples_3">Examples
</h3><div style=
"clear:left"></div>
808 <div class=
"dlist"><dl>
813 <div class=
"listingblock">
814 <div class=
"content">
815 <pre><tt>$ git status
<b><1></b>
816 $ git show-branch
<b><2></b>
817 $ mailx
<b><3></b>
818 & s
2 3 4 5 ./+to-apply
819 & s
7 8 ./+hold-linus
821 $ git checkout -b topic/one master
822 $ git am -
3 -i -s -u ./+to-apply
<b><4></b>
824 $ git checkout -b hold/linus
&& git am -
3 -i -s -u ./+hold-linus
<b><5></b>
825 $ git checkout topic/one
&& git rebase master
<b><6></b>
826 $ git checkout pu
&& git reset --hard next
<b><7></b>
827 $ git merge topic/one topic/two
&& git merge hold/linus
<b><8></b>
829 $ git cherry-pick master~
4 <b><9></b>
831 $ git tag -s -m
"GIT 0.99.9x" v0.99
.9x
<b><10></b>
832 $ git fetch ko
&& git show-branch master maint 'tags/ko-*'
<b><11></b>
833 $ git push ko
<b><12></b>
834 $ git push ko v0.99
.9x
<b><13></b></tt></pre>
836 <div class=
"colist arabic"><ol>
839 see what I was in the middle of doing, if any.
844 see what topic branches I have and think about how ready
850 read mails, save ones that are applicable, and save others
851 that are not quite ready.
856 apply them, interactively, with my sign-offs.
861 create topic branch as needed and apply, again with my
867 rebase internal topic branch that has not been merged to the
868 master, nor exposed as a part of a stable branch.
873 restart
<tt>pu
</tt> every time from the next.
878 and bundle topic branches still cooking.
883 backport a critical fix.
893 make sure I did not accidentally rewind master beyond what I
894 already pushed out.
<tt>ko
</tt> shorthand points at the repository I have
895 at kernel.org, and looks like this:
897 <div class=
"listingblock">
898 <div class=
"content">
899 <pre><tt>$ cat .git/remotes/ko
900 URL: kernel.org:/pub/scm/git/git.git
901 Pull: master:refs/tags/ko-master
902 Pull: next:refs/tags/ko-next
903 Pull: maint:refs/tags/ko-maint
907 Push: maint
</tt></pre>
909 <div class=
"paragraph"><p>In the output from
<tt>git show-branch
</tt>,
<tt>master
</tt> should have
910 everything
<tt>ko-master
</tt> has, and
<tt>next
</tt> should have
911 everything
<tt>ko-next
</tt> has.
</p></div>
915 push out the bleeding edge.
920 push the tag out, too.
927 <h2 id=
"_repository_administration_a_id_repository_administration_a">Repository Administration
<a id=
"Repository Administration"></a></h2>
928 <div class=
"sectionbody">
929 <div class=
"paragraph"><p>A repository administrator uses the following tools to set up
930 and maintain access to the repository by developers.
</p></div>
931 <div class=
"ulist"><ul>
934 <a href=
"git-daemon.html">git-daemon(
1)
</a> to allow anonymous download from
940 <a href=
"git-shell.html">git-shell(
1)
</a> can be used as a
<em>restricted login shell
</em>
941 for shared central repository users.
945 <div class=
"paragraph"><p><a href=
"howto/update-hook-example.txt">update hook howto
</a> has a good
946 example of managing a shared central repository.
</p></div>
947 <h3 id=
"_examples_4">Examples
</h3><div style=
"clear:left"></div>
948 <div class=
"dlist"><dl>
950 We assume the following in /etc/services
953 <div class=
"listingblock">
954 <div class=
"content">
955 <pre><tt>$ grep
9418 /etc/services
956 git
9418/tcp # Git Version Control System
</tt></pre>
960 Run git-daemon to serve /pub/scm from inetd.
963 <div class=
"listingblock">
964 <div class=
"content">
965 <pre><tt>$ grep git /etc/inetd.conf
966 git stream tcp nowait nobody \
967 /usr/bin/git-daemon git-daemon --inetd --export-all /pub/scm
</tt></pre>
969 <div class=
"paragraph"><p>The actual configuration line should be on one line.
</p></div>
972 Run git-daemon to serve /pub/scm from xinetd.
975 <div class=
"listingblock">
976 <div class=
"content">
977 <pre><tt>$ cat /etc/xinetd.d/git-daemon
979 # description: The git server offers access to git repositories
988 server = /usr/bin/git-daemon
989 server_args = --inetd --export-all --base-path=/pub/scm
990 log_on_failure += USERID
993 <div class=
"paragraph"><p>Check your xinetd(
8) documentation and setup, this is from a Fedora system.
994 Others might be different.
</p></div>
997 Give push/pull only access to developers.
1000 <div class=
"listingblock">
1001 <div class=
"content">
1002 <pre><tt>$ grep git /etc/passwd
<b><1></b>
1003 alice:x:
1000:
1000::/home/alice:/usr/bin/git-shell
1004 bob:x:
1001:
1001::/home/bob:/usr/bin/git-shell
1005 cindy:x:
1002:
1002::/home/cindy:/usr/bin/git-shell
1006 david:x:
1003:
1003::/home/david:/usr/bin/git-shell
1007 $ grep git /etc/shells
<b><2></b>
1008 /usr/bin/git-shell
</tt></pre>
1010 <div class=
"colist arabic"><ol>
1013 log-in shell is set to /usr/bin/git-shell, which does not
1014 allow anything but
<tt>git push
</tt> and
<tt>git pull
</tt>. The users should
1015 get an ssh access to the machine.
1020 in many distributions /etc/shells needs to list what is used
1026 <dt class=
"hdlist1">
1027 CVS-style shared repository.
1030 <div class=
"listingblock">
1031 <div class=
"content">
1032 <pre><tt>$ grep git /etc/group
<b><1></b>
1033 git:x:
9418:alice,bob,cindy,david
1035 $ ls -l
<b><2></b>
1036 lrwxrwxrwx
1 david git
17 Dec
4 22:
40 HEAD -
> refs/heads/master
1037 drwxrwsr-x
2 david git
4096 Dec
4 22:
40 branches
1038 -rw-rw-r--
1 david git
84 Dec
4 22:
40 config
1039 -rw-rw-r--
1 david git
58 Dec
4 22:
40 description
1040 drwxrwsr-x
2 david git
4096 Dec
4 22:
40 hooks
1041 -rw-rw-r--
1 david git
37504 Dec
4 22:
40 index
1042 drwxrwsr-x
2 david git
4096 Dec
4 22:
40 info
1043 drwxrwsr-x
4 david git
4096 Dec
4 22:
40 objects
1044 drwxrwsr-x
4 david git
4096 Nov
7 14:
58 refs
1045 drwxrwsr-x
2 david git
4096 Dec
4 22:
40 remotes
1046 $ ls -l hooks/update
<b><3></b>
1047 -r-xr-xr-x
1 david git
3536 Dec
4 22:
40 update
1048 $ cat info/allowed-users
<b><4></b>
1049 refs/heads/master alice\|cindy
1050 refs/heads/doc-update bob
1051 refs/tags/v[
0-
9]* david
</tt></pre>
1053 <div class=
"colist arabic"><ol>
1056 place the developers into the same git group.
1061 and make the shared repository writable by the group.
1066 use update-hook example by Carl from Documentation/howto/
1067 for branch policy control.
1072 alice and cindy can push into master, only bob can push into doc-update.
1073 david is the release manager and is the only person who can
1074 create and push version tags.
1079 <dt class=
"hdlist1">
1080 HTTP server to support dumb protocol transfer.
1083 <div class=
"listingblock">
1084 <div class=
"content">
1085 <pre><tt>dev$ git update-server-info
<b><1></b>
1086 dev$ ftp user@isp.example.com
<b><2></b>
1087 ftp
> cp -r .git /home/user/myproject.git
</tt></pre>
1089 <div class=
"colist arabic"><ol>
1092 make sure your info/refs and objects/info/packs are up-to-date
1097 upload to public HTTP server hosted by your ISP.
1105 <div id=
"footer-text">
1106 Last updated
2010-
11-
25 03:
13:
39 UTC