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