Everyday: some examples.
[git/git.git] / Documentation / everyday.txt
CommitLineData
db9536c8
JH
1Everyday GIT With 20 Commands Or So
2===================================
3
4GIT suite has over 100 commands, and the manual page for each of
5them discusses what the command does and how it is used in
6detail, but until you know what command should be used in order
7to achieve what you want to do, you cannot tell which manual
8page to look at, and if you know that already you do not need
9the manual.
10
11Does that mean you need to know all of them before you can use
12git? Not at all. Depending on the role you play, the set of
13commands you need to know is slightly different, but in any case
14what you need to learn is far smaller than the full set of
15commands to carry out your day-to-day work. This document is to
16serve as a cheat-sheet and a set of pointers for people playing
17various roles.
18
19<<Basic Repository>> commands are needed by people who has a
20repository --- that is everybody, because every working tree of
21git is a repository.
22
23In addition, <<Individual Developer (Standalone)>> commands are
24essential for anybody who makes a commit, even for somebody who
25works alone.
26
27If you work with other people, you will need commands listed in
28<<Individual Developer (Participant)>> section as well.
29
30People who play <<Integrator>> role need to learn some more
31commands in addition to the above.
32
33<<Repository Administration>> commands are for system
34administrators who are responsible to care and feed git
35repositories to support developers.
36
37
38Basic Repository[[Basic Repository]]
39------------------------------------
40
41Everybody uses these commands to feed and care git repositories.
42
43 * gitlink:git-init-db[1] or gitlink:git-clone[1] to create a
44 new repository.
45
46 * gitlink:git-fsck-objects[1] to validate the repository.
47
48 * gitlink:git-prune[1] to garbage collect crufts in the
49 repository.
50
51 * gitlink:git-repack[1] to pack loose objects for efficiency.
52
53Individual Developer (Standalone)[[Individual Developer (Standalone)]]
54----------------------------------------------------------------------
55
56A standalone individual developer does not exchange patches with
57other poeple, and works alone in a single repository, using the
58following commands.
59
60 * gitlink:git-show-branch[1] to see where you are.
61
db9536c8
JH
62 * gitlink:git-log[1] to see what happened.
63
64 * gitlink:git-whatchanged[1] to find out where things have
65 come from.
66
67 * gitlink:git-checkout[1] and gitlink:git-branch[1] to switch
68 branches.
69
44db136c
JH
70 * gitlink:git-add[1] and gitlink:git-update-index[1] to manage
71 the index file.
72
73 * gitlink:git-diff[1] and gitlink:git-status[1] to see what
74 you are in the middle of doing.
db9536c8
JH
75
76 * gitlink:git-commit[1] to advance the current branch.
77
78 * gitlink:git-reset[1] and gitlink:git-checkout[1] (with
79 pathname parameters) to undo changes.
80
81 * gitlink:git-pull[1] with "." as the remote to merge between
82 local branches.
83
84 * gitlink:git-rebase[1] to maintain topic branches.
85
86
44db136c
JH
87Examples
88~~~~~~~~
89
90* Extract a tarball and create a working tree and a new repository to keep track of it.
91------------
92$ tar zxf frotz.tar.gz
93$ cd frotz
94$ git-init-db
95$ git add .
96$ git commit -m 'import of frotz source tree.'
97------------
98
99* Create a topic branch and develop
100------------
101$ git checkout -b private
102$ edit/compile/test
103$ git diff <1>
104$ git checkout -- foo.c <2>
105$ edit/compile/test
106$ git commit -a -s <3>
107$ git checkout master <4>
108$ git pull . private <5>
109
110<1> to see what changes you are committing.
111<2> revert your botched changes in selected path "foo.c".
112<3> commit everything as you have tested.
113<4> switch to the master branch.
114<5> merge a topic branch into your master branch
115------------
116
117
db9536c8
JH
118Individual Developer (Participant)[[Individual Developer (Participant)]]
119------------------------------------------------------------------------
120
121A developer working as a participant in a group project needs to
122learn how to communicate with others, and uses these commands in
123addition to the ones needed by a standalone developer.
124
125 * gitlink:git-pull[1] from "origin" to keep up-to-date with
126 the upstream.
127
128 * gitlink:git-push[1] to shared repository if you adopt CVS
129 style shared repository workflow.
130
131 * gitlink:git-format-patch[1] to prepare e-mail submission, if
132 you adopt Linux kernel-style public forum workflow.
133
134
44db136c
JH
135Examples
136~~~~~~~~
137
138* Clone the upstream and work on it. Feed changes to upstream.
139------------
140$ git clone git://git.kernel.org/pub/scm/.../torvalds/linux-2.6 my2.6
141$ cd my2.6
142$ edit/compile/test; git commit -a -s <1>
143$ git format-patch master <2>
144$ git pull <3>
145$ git pull git://git.kernel.org/pub/.../jgarzik/libata-dev.git ALL <4>
146
147<1> repeat as needed.
148<2> extract patches from your branch for e-mail submission.
149<3> "pull" fetches from "origin" by default and merges.
150<4> fetch from a specific branch from a specific repository and and merge.
151------------
152
153* Branch off of a specific tag.
154------------
155$ git checkout -b private2.6.14 v2.6.14 <1>
156$ edit/compile/test; git commit -a
157$ git checkout master
158$ git format-patch -k -m --stdout v2.6.14..private2.6.14 |
159 git am -3 -k <2>
160<1> create a private branch based on a well known (but somewhat behind)
161tag.
162<2> forward port all changes in private2.6.14 branch to master
163branch without formal "merging".
164------------
165
166
db9536c8
JH
167Integrator[[Integrator]]
168------------------------
169
170A fairly central person acting as the integrator in a group
171project receives changes made by others, reviews and integrates
172them and publishes the result for others to use, using these
173commands in addition to the ones needed by participants.
174
175 * gitlink:git-am[1] to apply patches e-mailed in from your
176 contributors.
177
178 * gitlink:git-pull[1] to merge from your trusted lieutenants.
179
180 * gitlink:git-format-patch[1] to prepare and send suggested
181 alternative to contributors.
182
183 * gitlink:git-revert[1] to undo botched commits.
184
185 * gitlink:git-push[1] to publish the bleeding edge.
186
187
188Repository Administration[[Repository Administration]]
189------------------------------------------------------
190
191A repository administrator uses the following tools to set up
192and maintain access to the repository by developers.
193
194 * gitlink:git-daemon[1] to allow anonymous download from
195 repository.
196
197 * gitlink:git-shell[1] can be used as a 'restricted login shell'
198 for shared central repository users.
199
8b15e2fb
JH
200 * link:howto/update-hook-example.txt[update hook howto] has a
201 good example of managing a shared central repository.
db9536c8 202