@@ -22,11 +22,11 @@ Level | Precedence | Location
2222` local ` | highest | in your project's ` .git/config ` file
2323
2424```
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
3030```
3131
3232
@@ -53,8 +53,8 @@ someaccount@example.com
5353To set the same values to apply to any of your repositories:
5454
5555``` 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"
5858```
5959
6060Line 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
8686
8787#### Details
8888```
89- git init [project-name]
89+ # Create a new project directory
90+ $ git init [projectname]
91+ $ cd [projectname]
9092
91- cd [dir]
92- git init
93+ # or initialize an existing directory
94+ $ cd [existingprojectname]
95+ $ git init
9396
94- git clone [url] [optional-name]
97+ # or clone an existing repository
98+ $ git clone [url] [optional-name]
9599```
96100
97101## Repository internals
@@ -116,10 +120,10 @@ git clone [url] [optional-name]
116120
117121#### Details
118122```
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>"
123127```
124128
125129## Comparing changes
@@ -133,11 +137,11 @@ git commit -m"<message>"
133137
134138#### Details
135139```
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
141145```
142146
143147## Reviewing history
@@ -150,19 +154,22 @@ git diff --stat -w --color-words
150154
151155#### Details
152156```
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
166173```
167174
168175## Branching on the command line
@@ -176,12 +183,12 @@ git log --decorate
176183
177184#### Details
178185```
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
185192```
186193
187194## Switching branches & discarding changes
@@ -195,10 +202,14 @@ git branch --no-merged
195202
196203#### Details
197204```
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]
201210
211+ # Check out a detatched HEAD (unnamed point in time)
212+ $ git checkout [ref]
202213```
203214
204215## Remotes
@@ -210,10 +221,10 @@ git checkout [ref]
210221
211222#### Details
212223```
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>
217228```
218229
219230## Publishing changes
@@ -225,11 +236,11 @@ git remote rm <name>
225236
226237#### Details
227238```
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
233244```
234245
235246## Merging at the command line
@@ -241,19 +252,18 @@ git branch -a`
241252
242253#### Details
243254```
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
250258
251- git checkout --ours [file]
252- git checkout --theirs [file]
259+ $ git merge
260+ $ git merge -m<message>
253261
254- git add [file]
255- git commit
262+ $ git checkout --ours [file]
263+ $ git checkout --theirs [file]
256264
265+ $ git add [file]
266+ $ git commit
257267```
258268
259269## Fetching changes
@@ -264,8 +274,8 @@ git commit
264274
265275#### Details
266276```
267- git fetch [remote]
268- git branch -a
277+ $ git fetch [remote]
278+ $ git branch -a
269279```
270280
271281## Removing files
@@ -277,9 +287,9 @@ git branch -a
277287
278288#### Details
279289``` 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>
283293```
284294
285295## Moving files
@@ -290,12 +300,12 @@ git rm --cached -- <filename>
290300
291301#### Details
292302``` shell
293- mv < file> < newfilename>
294- git add -A .
303+ $ mv < file> < newfilename>
304+ $ git add -A .
295305# 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>
299309```
300310
301311## Undoing commits with ` revert ` and ` reset `
@@ -310,11 +320,11 @@ git log --follow <file>
310320
311321#### Details
312322``` shell
313- git revert < REF>
323+ $ git revert < REF>
314324
315- git reset --hard
316- git reset --mixed
317- git reset --soft
325+ $ git reset --hard
326+ $ git reset --mixed
327+ $ git reset --soft
318328```
319329
320330## Ignoring temporary files
@@ -328,16 +338,16 @@ git reset --soft
328338
329339#### Details
330340```
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"
335345```
336346
337347Global ignore file configuration:
338348
339349```
340- git config --global core.excludesfile <filepathandname>
350+ $ git config --global core.excludesfile <filepathandname>
341351```
342352
343353## Stashing in-progress changes
@@ -349,9 +359,9 @@ git config --global core.excludesfile <filepathandname>
349359
350360#### Details
351361```
352- git stash
353- git pop
354- git stash --include-untracked
362+ $ git stash
363+ $ git pop
364+ $ git stash --include-untracked
355365```
356366
357367## Recovering almost anything with the ` reflog `
@@ -362,10 +372,10 @@ git stash --include-untracked
362372
363373#### Details
364374```
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}
369379```
370380
371381## Pull requests
@@ -389,7 +399,7 @@ git checkout HEAD@{1}
389399
390400#### Details
391401```
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
395405```
0 commit comments