3
3
subsection: "cheat-sheet"
4
4
title: "Git Cheat Sheet"
5
5
url: /cheat-sheet.html
6
+ headings:
7
+ - text: "Getting Started"
8
+ id: "getting-started"
9
+ - text: "Prepare to Commit"
10
+ id: "prepare-to-commit"
11
+ - text: "Make Commits"
12
+ id: "make-commits"
13
+ - text: "Move Between Branches"
14
+ id: "move-between-branches"
15
+ - text: "Diff Staged/Unstaged Changes"
16
+ id: "diff-staged-unstaged-changes"
17
+ - text: "Diff Commits"
18
+ id: "diff-commits"
19
+ - text: "Ways to refer to a commit"
20
+ id: "ways-to-refer-to-a-commit"
21
+ - text: "Discard Your Changes"
22
+ id: "discard-your-changes"
23
+ - text: "Edit History"
24
+ id: "edit-history"
25
+ - text: "Code Archaeology"
26
+ id: "code-archaeology"
27
+ - text: "Combine Diverged Branches"
28
+ id: "combine-diverged-branches"
29
+ - text: "Restore an Old File"
30
+ id: "restore-an-old-file"
31
+ - text: "Add a Remote"
32
+ id: "add-a-remote"
33
+ - text: "Push Your Changes"
34
+ id: "push-your-changes"
35
+ - text: "Pull Changes"
36
+ id: "pull-changes"
37
+ - text: "Configure Git"
38
+ id: "configure-git"
39
+ - text: "Important Files"
40
+ id: "important-files"
6
41
---
7
42
8
43
< div id ="main " class ="cheat-sheet ">
9
44
< h1 > Git Cheat Sheet</ h1 >
10
45
11
46
< section >
12
- < h2 > Getting Started</ h2 >
47
+ < h2 id =" getting-started " > Getting Started</ h2 >
13
48
< div class ="item ">
14
49
< h3 > Start a new repo:</ h3 >
15
50
< code > git init</ code >
@@ -21,7 +56,7 @@ <h3>Clone an existing repo:</h3>
21
56
</ section >
22
57
23
58
< section >
24
- < h2 > Prepare to Commit</ h2 >
59
+ < h2 id =" prepare-to-commit " > Prepare to Commit</ h2 >
25
60
< div class ="item ">
26
61
< h3 > Add untracked file or unstaged changes:</ h3 >
27
62
< code > git add <file></ code >
@@ -63,7 +98,7 @@ <h3>Check what you added:</h3>
63
98
</ section >
64
99
65
100
< section >
66
- < h2 > Make Commits</ h2 >
101
+ < h2 id =" make-commits " > Make Commits</ h2 >
67
102
< div class ="item ">
68
103
< h3 > Make a commit (and open text editor to write message):</ h3 >
69
104
< code > git commit</ code >
@@ -79,7 +114,7 @@ <h3>Commit all unstaged changes:</h3>
79
114
</ section >
80
115
81
116
< section >
82
- < h2 > Move Between Branches</ h2 >
117
+ < h2 id =" move-between-branches " > Move Between Branches</ h2 >
83
118
< div class ="item ">
84
119
< h3 > Switch branches:</ h3 >
85
120
< code > git switch <name></ code >
@@ -111,7 +146,7 @@ <h3>Force delete a branch:</h3>
111
146
</ section >
112
147
113
148
< section >
114
- < h2 > Diff Staged/Unstaged Changes</ h2 >
149
+ < h2 id =" diff-staged-unstaged-changes " > Diff Staged/Unstaged Changes</ h2 >
115
150
< div class ="item ">
116
151
< h3 > Diff all staged and unstaged changes:</ h3 >
117
152
< code > git diff HEAD</ code >
@@ -127,7 +162,7 @@ <h3>Diff just unstaged changes:</h3>
127
162
</ section >
128
163
129
164
< section >
130
- < h2 > Diff Commits</ h2 >
165
+ < h2 id =" diff-commits " > Diff Commits</ h2 >
131
166
< div class ="item ">
132
167
< h3 > Show diff between a commit and its parent:</ h3 >
133
168
< code > git show <commit></ code >
@@ -147,7 +182,7 @@ <h3>Show a summary of a diff:</h3>
147
182
</ div >
148
183
</ section >
149
184
< section class ="commit-reference ">
150
- < h2 > Ways to refer to a commit</ h2 >
185
+ < h2 id =" ways-to-refer-to-a-commit " > Ways to refer to a commit</ h2 >
151
186
< p class ="intro ">
152
187
Every time we say < code > <commit></ code > , you can use any of these:
153
188
</ p >
@@ -174,7 +209,7 @@ <h2>Ways to refer to a commit</h2>
174
209
</ section >
175
210
176
211
< section >
177
- < h2 > Discard Your Changes</ h2 >
212
+ < h2 id =" discard-your-changes " > Discard Your Changes</ h2 >
178
213
< div class ="item ">
179
214
< h3 > Delete unstaged changes to one file:</ h3 >
180
215
< code > git checkout <file></ code >
@@ -198,7 +233,7 @@ <h3>'Stash' all staged and unstaged changes:</h3>
198
233
</ section >
199
234
200
235
< section >
201
- < h2 > Edit History</ h2 >
236
+ < h2 id =" edit-history " > Edit History</ h2 >
202
237
< div class ="item ">
203
238
< h3 > "Undo" the most recent commit (keep your working directory the same):</ h3 >
204
239
< code > git reset HEAD^</ code >
@@ -221,7 +256,7 @@ <h3>Change a commit message (or add a file you forgot):</h3>
221
256
</ section >
222
257
223
258
< section >
224
- < h2 > Code Archaeology</ h2 >
259
+ < h2 id =" code-archaeology " > Code Archaeology</ h2 >
225
260
< div class ="item ">
226
261
< h3 > Look at a branch's history:</ h3 >
227
262
< code > git log main</ code >
@@ -247,7 +282,7 @@ <h3>Show who last changed each line of a file:</h3>
247
282
</ section >
248
283
249
284
< section >
250
- < h2 > Combine Diverged Branches</ h2 >
285
+ < h2 id =" combine-diverged-branches " > Combine Diverged Branches</ h2 >
251
286
< div class ="item ">
252
287
< h3 > Combine with rebase:</ h3 >
253
288
< code > git switch banana</ code >
@@ -640,7 +675,7 @@ <h3>Copy one commit onto the current branch:</h3>
640
675
</ section >
641
676
642
677
< section >
643
- < h2 > Restore an Old File</ h2 >
678
+ < h2 id =" restore-an-old-file " > Restore an Old File</ h2 >
644
679
< div class ="item ">
645
680
< h3 > Get the version of a file from another commit:</ h3 >
646
681
< code > git checkout <commit> <file></ code >
@@ -650,14 +685,14 @@ <h3>Get the version of a file from another commit:</h3>
650
685
</ section >
651
686
652
687
< section >
653
- < h2 > Add a Remote</ h2 >
688
+ < h2 id =" add-a-remote " > Add a Remote</ h2 >
654
689
< div class ="item ">
655
690
< code > git remote add <name> <url></ code >
656
691
</ div >
657
692
</ section >
658
693
659
694
< section >
660
- < h2 > Push Your Changes</ h2 >
695
+ < h2 id =" push-your-changes " > Push Your Changes</ h2 >
661
696
< div class ="item ">
662
697
< h3 > Push the < code > main</ code > branch to the remote < code > origin</ code > :</ h3 >
663
698
< code > git push origin main</ code >
@@ -681,7 +716,7 @@ <h3>Push tags:</h3>
681
716
</ section >
682
717
683
718
< section >
684
- < h2 > Pull Changes</ h2 >
719
+ < h2 id =" pull-changes " > Pull Changes</ h2 >
685
720
< div class ="item ">
686
721
< h3 > Fetch changes (but don't change any of your local branches):</ h3 >
687
722
< code > git fetch origin main</ code >
@@ -703,7 +738,7 @@ <h3>Fetch all branches:</h3>
703
738
</ section >
704
739
705
740
< section >
706
- < h2 > Configure Git</ h2 >
741
+ < h2 id =" configure-git " > Configure Git</ h2 >
707
742
< div class ="item ">
708
743
< h3 > Set a config option:</ h3 >
709
744
< code > git config user.name 'Your Name'</ code >
@@ -723,7 +758,7 @@ <h3>See all possible config options:</h3>
723
758
</ section >
724
759
725
760
< section >
726
- < h2 > Important Files</ h2 >
761
+ < h2 id =" important-files " > Important Files</ h2 >
727
762
< div class ="item ">
728
763
< h3 > Local git config:</ h3 >
729
764
< code > .git/config</ code >
0 commit comments