@@ -22,11 +22,11 @@ Level | Precedence | Location
22
22
` local ` | highest | in your project's ` .git/config ` file
23
23
24
24
```
25
- git config --list
26
- git config user.name
27
- git config user.email
28
- git config --global core.autocrlf <value>
29
- git config --global color.ui auto
25
+ $ git config --list
26
+ $ git config user.name
27
+ $ git config user.email
28
+ $ git config --global core.autocrlf <value>
29
+ $ git config --global color.ui auto
30
30
```
31
31
32
32
53
53
To set the same values to apply to any of your repositories:
54
54
55
55
``` shell
56
- git config --global user.name " your name"
57
- git config --global user.email " your@email"
56
+ $ git config --global user.name " your name"
57
+ $ git config --global user.email " your@email"
58
58
```
59
59
60
60
Line endings and color display are two of the most common settings users choose to set early in their use of Git.
@@ -86,12 +86,16 @@ $ git config --list
86
86
87
87
#### Details
88
88
```
89
- git init [project-name]
89
+ # Create a new project directory
90
+ $ git init [projectname]
91
+ $ cd [projectname]
90
92
91
- cd [dir]
92
- git init
93
+ # or initialize an existing directory
94
+ $ cd [existingprojectname]
95
+ $ git init
93
96
94
- git clone [url] [optional-name]
97
+ # or clone an existing repository
98
+ $ git clone [url] [optional-name]
95
99
```
96
100
97
101
## Repository internals
@@ -116,10 +120,10 @@ git clone [url] [optional-name]
116
120
117
121
#### Details
118
122
```
119
- git status
120
- git add <filename>
121
- git commit
122
- git commit -m"<message>"
123
+ $ git status
124
+ $ git add <filename>
125
+ $ git commit
126
+ $ git commit -m"<message>"
123
127
```
124
128
125
129
## Comparing changes
@@ -133,11 +137,11 @@ git commit -m"<message>"
133
137
134
138
#### Details
135
139
```
136
- git diff
137
- git diff --staged
138
- git diff HEAD
139
- git diff [file]
140
- git diff --stat -w --color-words
140
+ $ git diff
141
+ $ git diff --staged
142
+ $ git diff HEAD
143
+ $ git diff [file]
144
+ $ git diff --stat -w --color-words
141
145
```
142
146
143
147
## Reviewing history
@@ -150,19 +154,22 @@ git diff --stat -w --color-words
150
154
151
155
#### Details
152
156
```
153
- git log
154
- git log -<n>
155
- git log --stat
156
- git log --patch
157
- git log --all
158
- git log --author=<committer>
159
- git log --format= full, fuller, raw
160
- git log --diff-filter=[A|M|D]
161
- git log -S<StringInPatch> Search for string match _in_ patch
162
- git log -G="<pattern>" Listing patch change sets
163
- git log --word-diff --patch
164
- git log --graph
165
- git log --decorate
157
+ $ git log
158
+ $ git log -<n>
159
+ $ git log --stat
160
+ $ git log --patch
161
+ $ git log --all
162
+ $ git log --author=<author>
163
+ $ git log --committer=<committer>
164
+ $ git log --format=full
165
+ $ git log --format=fuller
166
+ $ git log --format=raw
167
+ $ git log --diff-filter=[A|M|D]
168
+ $ git log -S<StringInPatch>
169
+ $ git log -G="<regexpattern>"
170
+ $ git log --word-diff --patch
171
+ $ git log --graph
172
+ $ git log --decorate
166
173
```
167
174
168
175
## Branching on the command line
@@ -176,12 +183,12 @@ git log --decorate
176
183
177
184
#### Details
178
185
```
179
- git branch
180
- git branch <name> <ref>
181
- git branch -d <name>
182
- git branch -m <old> <new>
183
- git branch --merged
184
- git branch --no-merged
186
+ $ git branch
187
+ $ git branch <name> <ref>
188
+ $ git branch -d <name>
189
+ $ git branch -m <old> <new>
190
+ $ git branch --merged
191
+ $ git branch --no-merged
185
192
```
186
193
187
194
## Switching branches & discarding changes
@@ -195,10 +202,14 @@ git branch --no-merged
195
202
196
203
#### Details
197
204
```
198
- git checkout [branch]
199
- git checkout -- [file]
200
- git checkout [ref]
205
+ # Check out (toggle to) an existing branch
206
+ $ git checkout [branch]
207
+
208
+ # Check out a single file from HEAD
209
+ $ git checkout -- [file]
201
210
211
+ # Check out a detatched HEAD (unnamed point in time)
212
+ $ git checkout [ref]
202
213
```
203
214
204
215
## Remotes
@@ -210,10 +221,10 @@ git checkout [ref]
210
221
211
222
#### Details
212
223
```
213
- git clone -o github <URL>
214
- git remote add <name> <path>
215
- git ls-remote <name>
216
- git remote rm <name>
224
+ $ git clone -o github <URL>
225
+ $ git remote add <name> <path>
226
+ $ git ls-remote <name>
227
+ $ git remote rm <name>
217
228
```
218
229
219
230
## Publishing changes
@@ -225,11 +236,11 @@ git remote rm <name>
225
236
226
237
#### Details
227
238
```
228
- git push -u origin master
229
- git config --global push.default matching
230
- git config --global push.default simple
231
- git branch -r
232
- git branch -a`
239
+ $ git push -u origin master
240
+ $ git config --global push.default matching
241
+ $ git config --global push.default simple
242
+ $ git branch -r
243
+ $ git branch -a
233
244
```
234
245
235
246
## Merging at the command line
@@ -241,19 +252,18 @@ git branch -a`
241
252
242
253
#### Details
243
254
```
244
- git pull origin
245
- git pull
246
- git pull --rebase
247
-
248
- git merge
249
- git merge -m<message>
255
+ $ git pull origin
256
+ $ git pull
257
+ $ git pull --rebase
250
258
251
- git checkout --ours [file]
252
- git checkout --theirs [file]
259
+ $ git merge
260
+ $ git merge -m<message>
253
261
254
- git add [file]
255
- git commit
262
+ $ git checkout --ours [file]
263
+ $ git checkout --theirs [file]
256
264
265
+ $ git add [file]
266
+ $ git commit
257
267
```
258
268
259
269
## Fetching changes
@@ -264,8 +274,8 @@ git commit
264
274
265
275
#### Details
266
276
```
267
- git fetch [remote]
268
- git branch -a
277
+ $ git fetch [remote]
278
+ $ git branch -a
269
279
```
270
280
271
281
## Removing files
@@ -277,9 +287,9 @@ git branch -a
277
287
278
288
#### Details
279
289
``` shell
280
- git add -u .
281
- git rm < file>
282
- git rm --cached -- < filename>
290
+ $ git add -u .
291
+ $ git rm < file>
292
+ $ git rm --cached -- < filename>
283
293
```
284
294
285
295
## Moving files
@@ -290,12 +300,12 @@ git rm --cached -- <filename>
290
300
291
301
#### Details
292
302
``` shell
293
- mv < file> < newfilename>
294
- git add -A .
303
+ $ mv < file> < newfilename>
304
+ $ git add -A .
295
305
# or
296
- git mv < file> < file>
297
- git log --stat -M
298
- git log --follow < file>
306
+ $ git mv < file> < file>
307
+ $ git log --stat -M
308
+ $ git log --follow < file>
299
309
```
300
310
301
311
## Undoing commits with ` revert ` and ` reset `
@@ -310,11 +320,11 @@ git log --follow <file>
310
320
311
321
#### Details
312
322
``` shell
313
- git revert < REF>
323
+ $ git revert < REF>
314
324
315
- git reset --hard
316
- git reset --mixed
317
- git reset --soft
325
+ $ git reset --hard
326
+ $ git reset --mixed
327
+ $ git reset --soft
318
328
```
319
329
320
330
## Ignoring temporary files
@@ -328,16 +338,16 @@ git reset --soft
328
338
329
339
#### Details
330
340
```
331
- touch .gitignore
332
- echo '*.log' >> .gitignore
333
- git add .gitignore
334
- git commit -m "Ignoring log files"
341
+ $ touch .gitignore
342
+ $ echo '*.log' >> .gitignore
343
+ $ git add .gitignore
344
+ $ git commit -m "Ignoring log files"
335
345
```
336
346
337
347
Global ignore file configuration:
338
348
339
349
```
340
- git config --global core.excludesfile <filepathandname>
350
+ $ git config --global core.excludesfile <filepathandname>
341
351
```
342
352
343
353
## Stashing in-progress changes
@@ -349,9 +359,9 @@ git config --global core.excludesfile <filepathandname>
349
359
350
360
#### Details
351
361
```
352
- git stash
353
- git pop
354
- git stash --include-untracked
362
+ $ git stash
363
+ $ git pop
364
+ $ git stash --include-untracked
355
365
```
356
366
357
367
## Recovering almost anything with the ` reflog `
@@ -362,10 +372,10 @@ git stash --include-untracked
362
372
363
373
#### Details
364
374
```
365
- git reflog
366
- git reflog --all
367
- git config --global alias.undo "reset HEAD@{1}"
368
- git checkout HEAD@{1}
375
+ $ git reflog
376
+ $ git reflog --all
377
+ $ git config --global alias.undo "reset HEAD@{1}"
378
+ $ git checkout HEAD@{1}
369
379
```
370
380
371
381
## Pull requests
@@ -389,7 +399,7 @@ git checkout HEAD@{1}
389
399
390
400
#### Details
391
401
```
392
- git config --global alias.l "log --oneline --stat"
393
- git config alias.s "status -s"
394
- git s
402
+ $ git config --global alias.l "log --oneline --stat"
403
+ $ git config alias.s "status -s"
404
+ $ git s
395
405
```
0 commit comments