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