Merge branch 'jc/push-cert' into pu
[git/jrn.git] / Documentation / giteveryday.txt
blobda97b7fad7eb378037d9796299ebe3e44dbb0bc4
1 giteveryday(7)
2 ===============
4 NAME
5 ----
6 giteveryday - A useful minimum set of commands for Everyday Git
8 SYNOPSIS
9 --------
11 Everyday Git With 20 Commands Or So
13 DESCRIPTION
14 -----------
15 <<STANDALONE,Individual Developer (Standalone)>> commands are essential for
16 anybody who makes a commit, even for somebody who works alone.
18 If you work with other people, you will need commands listed in
19 the <<PARTICIPANT,Individual Developer (Participant)>> section as well.
21 People who play the <<INTEGRATOR,Integrator>> role need to learn some more
22 commands in addition to the above.
24 <<ADMINISTRATION,Repository Administration>> commands are for system
25 administrators who are responsible for the care and feeding
26 of Git repositories.
29 Individual Developer (Standalone)[[STANDALONE]]
30 -----------------------------------------------
32 A standalone individual developer does not exchange patches with
33 other people, and works alone in a single repository, using the
34 following commands.
36   * linkgit:git-init[1] to create a new repository.
38   * linkgit:git-show-branch[1] to see where you are.
40   * linkgit:git-log[1] to see what happened.
42   * linkgit:git-checkout[1] and linkgit:git-branch[1] to switch
43     branches.
45   * linkgit:git-add[1] to manage the index file.
47   * linkgit:git-diff[1] and linkgit:git-status[1] to see what
48     you are in the middle of doing.
50   * linkgit:git-commit[1] to advance the current branch.
52   * linkgit:git-reset[1] and linkgit:git-checkout[1] (with
53     pathname parameters) to undo changes.
55   * linkgit:git-merge[1] to merge between local branches.
57   * linkgit:git-rebase[1] to maintain topic branches.
59   * linkgit:git-tag[1] to mark known point.
61 Examples
62 ~~~~~~~~
64 Use a tarball as a starting point for a new repository.::
66 ------------
67 $ tar zxf frotz.tar.gz
68 $ cd frotz
69 $ git init
70 $ git add . <1>
71 $ git commit -m "import of frotz source tree."
72 $ git tag v2.43 <2>
73 ------------
75 <1> add everything under the current directory.
76 <2> make a lightweight, unannotated tag.
78 Create a topic branch and develop.::
80 ------------
81 $ git checkout -b alsa-audio <1>
82 $ edit/compile/test
83 $ git checkout -- curses/ux_audio_oss.c <2>
84 $ git add curses/ux_audio_alsa.c <3>
85 $ edit/compile/test
86 $ git diff HEAD <4>
87 $ git commit -a -s <5>
88 $ edit/compile/test
89 $ git reset --soft HEAD^ <6>
90 $ edit/compile/test
91 $ git diff ORIG_HEAD <7>
92 $ git commit -a -c ORIG_HEAD <8>
93 $ git checkout master <9>
94 $ git merge alsa-audio <10>
95 $ git log --since='3 days ago' <11>
96 $ git log v2.43.. curses/ <12>
97 ------------
99 <1> create a new topic branch.
100 <2> revert your botched changes in `curses/ux_audio_oss.c`.
101 <3> you need to tell Git if you added a new file; removal and
102 modification will be caught if you do `git commit -a` later.
103 <4> to see what changes you are committing.
104 <5> commit everything as you have tested, with your sign-off.
105 <6> take the last commit back, keeping what is in the working tree.
106 <7> look at the changes since the premature commit we took back.
107 <8> redo the commit undone in the previous step, using the message
108 you originally wrote.
109 <9> switch to the master branch.
110 <10> merge a topic branch into your master branch.
111 <11> review commit logs; other forms to limit output can be
112 combined and include `--max-count=10` (show 10 commits),
113 `--until=2005-12-10`, etc.
114 <12> view only the changes that touch what's in `curses/`
115 directory, since `v2.43` tag.
118 Individual Developer (Participant)[[PARTICIPANT]]
119 -------------------------------------------------
121 A developer working as a participant in a group project needs to
122 learn how to communicate with others, and uses these commands in
123 addition to the ones needed by a standalone developer.
125   * linkgit:git-clone[1] from the upstream to prime your local
126     repository.
128   * linkgit:git-pull[1] and linkgit:git-fetch[1] from "origin"
129     to keep up-to-date with the upstream.
131   * linkgit:git-push[1] to shared repository, if you adopt CVS
132     style shared repository workflow.
134   * linkgit:git-format-patch[1] to prepare e-mail submission, if
135     you adopt Linux kernel-style public forum workflow.
137 Examples
138 ~~~~~~~~
140 Clone the upstream and work on it.  Feed changes to upstream.::
142 ------------
143 $ git clone git://git.kernel.org/pub/scm/.../torvalds/linux-2.6 my2.6
144 $ cd my2.6
145 $ edit/compile/test; git commit -a -s <1>
146 $ git format-patch origin <2>
147 $ git pull <3>
148 $ git log -p ORIG_HEAD.. arch/i386 include/asm-i386 <4>
149 $ git pull git://git.kernel.org/pub/.../jgarzik/libata-dev.git ALL <5>
150 $ git reset --hard ORIG_HEAD <6>
151 $ git gc <7>
152 $ git fetch --tags <8>
153 ------------
155 <1> repeat as needed.
156 <2> extract patches from your branch for e-mail submission.
157 <3> `git pull` fetches from `origin` by default and merges into the
158 current branch.
159 <4> immediately after pulling, look at the changes done upstream
160 since last time we checked, only in the
161 area we are interested in.
162 <5> fetch from a specific branch from a specific repository and merge.
163 <6> revert the pull.
164 <7> garbage collect leftover objects from reverted pull.
165 <8> from time to time, obtain official tags from the `origin`
166 and store them under `.git/refs/tags/`.
169 Push into another repository.::
171 ------------
172 satellite$ git clone mothership:frotz frotz <1>
173 satellite$ cd frotz
174 satellite$ git config --get-regexp '^(remote|branch)\.' <2>
175 remote.origin.url mothership:frotz
176 remote.origin.fetch refs/heads/*:refs/remotes/origin/*
177 branch.master.remote origin
178 branch.master.merge refs/heads/master
179 satellite$ git config remote.origin.push \
180            master:refs/remotes/satellite/master <3>
181 satellite$ edit/compile/test/commit
182 satellite$ git push origin <4>
184 mothership$ cd frotz
185 mothership$ git checkout master
186 mothership$ git merge satellite/master <5>
187 ------------
189 <1> mothership machine has a frotz repository under your home
190 directory; clone from it to start a repository on the satellite
191 machine.
192 <2> clone sets these configuration variables by default.
193 It arranges `git pull` to fetch and store the branches of mothership
194 machine to local `remotes/origin/*` remote-tracking branches.
195 <3> arrange `git push` to push local `master` branch to
196 `remotes/satellite/master` branch of the mothership machine.
197 <4> push will stash our work away on `remotes/satellite/master`
198 remote-tracking branch on the mothership machine.  You could use this
199 as a back-up method.
200 <5> on mothership machine, merge the work done on the satellite
201 machine into the master branch.
203 Branch off of a specific tag.::
205 ------------
206 $ git checkout -b private2.6.14 v2.6.14 <1>
207 $ edit/compile/test; git commit -a
208 $ git checkout master
209 $ git format-patch -k -m --stdout v2.6.14..private2.6.14 |
210   git am -3 -k <2>
211 ------------
213 <1> create a private branch based on a well known (but somewhat behind)
214 tag.
215 <2> forward port all changes in `private2.6.14` branch to `master` branch
216 without a formal "merging".
219 Integrator[[INTEGRATOR]]
220 ------------------------
222 A fairly central person acting as the integrator in a group
223 project receives changes made by others, reviews and integrates
224 them and publishes the result for others to use, using these
225 commands in addition to the ones needed by participants.
227   * linkgit:git-am[1] to apply patches e-mailed in from your
228     contributors.
230   * linkgit:git-pull[1] to merge from your trusted lieutenants.
232   * linkgit:git-format-patch[1] to prepare and send suggested
233     alternative to contributors.
235   * linkgit:git-revert[1] to undo botched commits.
237   * linkgit:git-push[1] to publish the bleeding edge.
240 Examples
241 ~~~~~~~~
243 My typical Git day.::
245 ------------
246 $ git status <1>
247 $ git show-branch <2>
248 $ mailx <3>
249 & s 2 3 4 5 ./+to-apply
250 & s 7 8 ./+hold-linus
251 & q
252 $ git checkout -b topic/one master
253 $ git am -3 -i -s -u ./+to-apply <4>
254 $ compile/test
255 $ git checkout -b hold/linus && git am -3 -i -s -u ./+hold-linus <5>
256 $ git checkout topic/one && git rebase master <6>
257 $ git checkout pu && git reset --hard next <7>
258 $ git merge topic/one topic/two && git merge hold/linus <8>
259 $ git checkout maint
260 $ git cherry-pick master~4 <9>
261 $ compile/test
262 $ git tag -s -m "GIT 0.99.9x" v0.99.9x <10>
263 $ git fetch ko && git show-branch master maint 'tags/ko-*' <11>
264 $ git push ko <12>
265 $ git push ko v0.99.9x <13>
266 ------------
268 <1> see what I was in the middle of doing, if any.
269 <2> see what topic branches I have and think about how ready
270 they are.
271 <3> read mails, save ones that are applicable, and save others
272 that are not quite ready.
273 <4> apply them, interactively, with my sign-offs.
274 <5> create topic branch as needed and apply, again with my
275 sign-offs.
276 <6> rebase internal topic branch that has not been merged to the
277 master or exposed as a part of a stable branch.
278 <7> restart `pu` every time from the next.
279 <8> and bundle topic branches still cooking.
280 <9> backport a critical fix.
281 <10> create a signed tag.
282 <11> make sure I did not accidentally rewind master beyond what I
283 already pushed out.  `ko` shorthand points at the repository I have
284 at kernel.org, and looks like this:
286 ------------
287 $ cat .git/remotes/ko
288 URL: kernel.org:/pub/scm/git/git.git
289 Pull: master:refs/tags/ko-master
290 Pull: next:refs/tags/ko-next
291 Pull: maint:refs/tags/ko-maint
292 Push: master
293 Push: next
294 Push: +pu
295 Push: maint
296 ------------
298 In the output from `git show-branch`, `master` should have
299 everything `ko-master` has, and `next` should have
300 everything `ko-next` has.
302 <12> push out the bleeding edge.
303 <13> push the tag out, too.
306 Repository Administration[[ADMINISTRATION]]
307 -------------------------------------------
309 A repository administrator uses the following tools to set up
310 and maintain access to the repository by developers.
312   * linkgit:git-daemon[1] to allow anonymous download from
313     repository.
315   * linkgit:git-shell[1] can be used as a 'restricted login shell'
316     for shared central repository users.
318 link:howto/update-hook-example.html[update hook howto] has a good
319 example of managing a shared central repository.
322 Examples
323 ~~~~~~~~
324 We assume the following in /etc/services::
326 ------------
327 $ grep 9418 /etc/services
328 git             9418/tcp                # Git Version Control System
329 ------------
331 Run git-daemon to serve /pub/scm from inetd.::
333 ------------
334 $ grep git /etc/inetd.conf
335 git     stream  tcp     nowait  nobody \
336   /usr/bin/git-daemon git-daemon --inetd --export-all /pub/scm
337 ------------
339 The actual configuration line should be on one line.
341 Run git-daemon to serve /pub/scm from xinetd.::
343 ------------
344 $ cat /etc/xinetd.d/git-daemon
345 # default: off
346 # description: The Git server offers access to Git repositories
347 service git
349         disable = no
350         type            = UNLISTED
351         port            = 9418
352         socket_type     = stream
353         wait            = no
354         user            = nobody
355         server          = /usr/bin/git-daemon
356         server_args     = --inetd --export-all --base-path=/pub/scm
357         log_on_failure  += USERID
359 ------------
361 Check your xinetd(8) documentation and setup, this is from a Fedora system.
362 Others might be different.
364 Give push/pull only access to developers.::
366 ------------
367 $ grep git /etc/passwd <1>
368 alice:x:1000:1000::/home/alice:/usr/bin/git-shell
369 bob:x:1001:1001::/home/bob:/usr/bin/git-shell
370 cindy:x:1002:1002::/home/cindy:/usr/bin/git-shell
371 david:x:1003:1003::/home/david:/usr/bin/git-shell
372 $ grep git /etc/shells <2>
373 /usr/bin/git-shell
374 ------------
376 <1> log-in shell is set to /usr/bin/git-shell, which does not
377 allow anything but `git push` and `git pull`.  The users should
378 get an ssh access to the machine.
379 <2> in many distributions /etc/shells needs to list what is used
380 as the login shell.
382 CVS-style shared repository.::
384 ------------
385 $ grep git /etc/group <1>
386 git:x:9418:alice,bob,cindy,david
387 $ cd /home/devo.git
388 $ ls -l <2>
389   lrwxrwxrwx   1 david git    17 Dec  4 22:40 HEAD -> refs/heads/master
390   drwxrwsr-x   2 david git  4096 Dec  4 22:40 branches
391   -rw-rw-r--   1 david git    84 Dec  4 22:40 config
392   -rw-rw-r--   1 david git    58 Dec  4 22:40 description
393   drwxrwsr-x   2 david git  4096 Dec  4 22:40 hooks
394   -rw-rw-r--   1 david git 37504 Dec  4 22:40 index
395   drwxrwsr-x   2 david git  4096 Dec  4 22:40 info
396   drwxrwsr-x   4 david git  4096 Dec  4 22:40 objects
397   drwxrwsr-x   4 david git  4096 Nov  7 14:58 refs
398   drwxrwsr-x   2 david git  4096 Dec  4 22:40 remotes
399 $ ls -l hooks/update <3>
400   -r-xr-xr-x   1 david git  3536 Dec  4 22:40 update
401 $ cat info/allowed-users <4>
402 refs/heads/master       alice\|cindy
403 refs/heads/doc-update   bob
404 refs/tags/v[0-9]*       david
405 ------------
407 <1> place the developers into the same git group.
408 <2> and make the shared repository writable by the group.
409 <3> use update-hook example by Carl from Documentation/howto/
410 for branch policy control.
411 <4> alice and cindy can push into master, only bob can push into doc-update.
412 david is the release manager and is the only person who can
413 create and push version tags.
415 HTTP server to support dumb protocol transfer.::
417 ------------
418 dev$ git update-server-info <1>
419 dev$ ftp user@isp.example.com <2>
420 ftp> cp -r .git /home/user/myproject.git
421 ------------
423 <1> make sure your info/refs and objects/info/packs are up-to-date
424 <2> upload to public HTTP server hosted by your ISP.
428 Part of the linkgit:git[1] suite