interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / Documentation / giteveryday.adoc

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