1
1
# GitHub Git Cheat Sheet
2
2
3
- Git is the open source distributed version control system that facilitates GitHub activities on your laptop or desktop. This cheat sheet summarizes commonly- used Git command line instructions for quick reference.
3
+ Git is the open source distributed version control system that facilitates GitHub activities on your laptop or desktop. This cheat sheet summarizes commonly used Git command line instructions for quick reference.
4
4
5
5
## Install git
6
- GitHub provides desktop clients that include a graphical user interface for the most common repository actions and an automatically updating command line edition of Git for advanced scenarios.
6
+ GitHub provides desktop clients that include a graphical user interface for the most common repository actions and an automatically updating command line edition of Git for advanced scenarios.
7
7
8
8
### GitHub for Windows
9
9
http://windows.github.com
@@ -19,143 +19,212 @@ http://git-scm.com
19
19
## Configure tooling
20
20
Configure user information for all local repositories
21
21
22
- ``` git config --global user.name "[name]" ```
23
- Set the name you want attached to your commit transactions
24
22
25
- ``` git config --global user.email "[email address]" ```
26
- Set the email you want attached to your commit transactions
23
+ ``` $ git config --global user.name "[name]" ```
27
24
28
- ``` git config --global color.ui auto ```
29
- Enable helpful colorization of command line output
25
+ Sets the name you want attached to your commit transactions
26
+
27
+
28
+ ``` $ git config --global user.email "[email address]" ```
29
+
30
+ Sets the email you want attached to your commit transactions
31
+
32
+
33
+ ``` $ git config --global color.ui auto ```
34
+
35
+ Enables helpful colorization of command line output
30
36
31
37
32
38
## Create repositories
33
39
Start a new repository or obtain one from an existing URL
34
40
35
- ``` git init [project-name] ```
36
- Create a new local repository with the specified name
37
41
38
- ``` git clone [url] ```
39
- Download a project and its entire version history
42
+ ``` $ git init [project-name] ```
43
+
44
+ Creates a new local repository with the specified name
45
+
46
+
47
+ ``` $ git clone [url] ```
48
+
49
+ Downloads a project and its entire version history
40
50
41
51
## Make changes
42
52
Review edits and craft a commit transaction
43
53
44
- ``` git status ```
45
- List all new or modified files to be committed
46
54
47
- ``` git diff ```
48
- Show file differences not yet staged
55
+ ``` $ git status ```
56
+
57
+ Lists all new or modified files to be committed
58
+
59
+
60
+ ``` $ git diff ```
61
+
62
+ Shows file differences not yet staged
63
+
64
+
65
+ ``` $ git add [file] ```
66
+
67
+ Snapshots the file in preparation for versioning
68
+
49
69
50
- ``` git add [file] ```
51
- Snapshot the file in preparation for versioning
70
+ ``` $ git diff --staged ```
52
71
53
- ``` git diff --staged ```
54
- Show file differences between staging and the last file version
72
+ Shows file differences between staging and the last file version
55
73
56
- ``` git reset [file] ```
57
- Unstage the file, but preserve its contents
58
74
59
- ``` git commit -m"[descriptive message]" ```
60
- Record file snapshots permanently in version history
75
+ ``` $ git reset [file] ```
76
+
77
+ Unstages the file, but preserves its contents
78
+
79
+
80
+ ``` $ git commit -m"[descriptive message]" ```
81
+
82
+ Records file snapshots permanently in version history
61
83
62
84
## Group changes
63
85
Name a series of commits and combine completed efforts
64
86
65
- ``` git branch ```
66
- List all local branches in the current repository
67
87
68
- ``` git branch [branch-name] ```
69
- Create a new branch
88
+ ``` $ git branch ```
89
+
90
+ Lists all local branches in the current repository
91
+
92
+
93
+ ``` $ git branch [branch-name] ```
94
+
95
+ Creates a new branch
96
+
70
97
71
- ``` git checkout [branch-name] ```
72
- Switch to the specified branch and update working directory
98
+ ``` $ git checkout [branch-name] ```
73
99
74
- ``` git merge [branch-name] ```
75
- Combine the specified branch’s history into the current branch
100
+ Switches to the specified branch and updates working directory
76
101
77
- ``` git branch -d [branch-name] ```
78
- Delete the specified branch
79
102
103
+ ``` $ git merge [branch-name] ```
80
104
81
- ## Refactor filenames
105
+ Combines the specified branch’s history into the current branch
106
+
107
+
108
+ ``` $ git branch -d [branch-name] ```
109
+
110
+ Deletes the specified branch
111
+
112
+
113
+ ## Refactor file names
82
114
Relocate and remove versioned files
83
115
84
- ``` git rm [file] ```
85
- Delete the file from the working directory and stage the deletion
86
116
87
- ``` git rm --cached [file] ```
88
- Remove from version control but preserve the file locally
117
+ ``` $ git rm [file] ```
118
+
119
+ Deletes the file from the working directory and stages the deletion
120
+
121
+
122
+ ``` $ git rm --cached [file] ```
89
123
90
- ``` git mv [file-original] [file-renamed] ```
91
- Change the filename and prepare it for commit
124
+ Removes from version control but preserves the file locally
92
125
93
- ## Supress tracking
126
+
127
+ ``` $ git mv [file-original] [file-renamed] ```
128
+
129
+ Changes the file name and prepare it for commit
130
+
131
+ ## Suppress tracking
94
132
Exclude temporary files and paths
95
133
96
134
```
97
135
*.log
98
136
build/
99
137
temp-*
100
138
```
139
+
101
140
A text file named ` .gitignore ` suppresses accidental versioning of files and paths matching the specified patterns
102
141
103
- ``` git ls-files --other --ignored --exclude-standard ```
104
- List all ignored files in this project
142
+
143
+ ``` $ git ls-files --other --ignored --exclude-standard ```
144
+
145
+ Lists all ignored files in this project
105
146
106
147
## Save fragments
107
148
Shelve and restore incomplete changes
108
149
109
- ``` git stash ```
110
- Temporarily store all modified tracked files
111
150
112
- ``` git stash pop ```
113
- Restore the most recently stashed files
151
+ ``` $ git stash ```
152
+
153
+ Temporarily stores all modified tracked files
154
+
155
+
156
+ ``` $ git stash pop ```
114
157
115
- ``` git stash list ```
116
- List all stashed changesets
158
+ Restores the most recent stashed files
117
159
118
- ``` git stash drop ```
119
- Discard the most recently stashed changeset
160
+
161
+ ``` $ git stash list ```
162
+
163
+ Lists all stashed changesets
164
+
165
+
166
+ ``` $ git stash drop ```
167
+
168
+ Discards the most recently stashed changeset
120
169
121
170
## Review history
122
171
Browse and inspect the evolution of project files
123
172
124
- ``` git log ```
125
- List version history for the current branch
126
173
127
- ``` git log --follow [file] ```
128
- List version history for a file, including renames
174
+ ``` $ git log ```
175
+
176
+ Lists version history for the current branch
177
+
178
+
179
+ ``` $ git log --follow [file] ```
129
180
130
- ``` git diff [first-branch]...[second-branch] ```
131
- Show content differences between two branches
181
+ Lists version history for a file, including renames
132
182
133
- ``` git show [commit] ```
134
- Output metadata and content changes of the specified commit
183
+
184
+ ``` $ git diff [first-branch]...[second-branch] ```
185
+
186
+ Shows content differences between two branches
187
+
188
+
189
+ ``` $ git show [commit] ```
190
+
191
+ Outputs metadata and content changes of the specified commit
135
192
136
193
## Redo commits
137
194
Erase mistakes and craft replacement history
138
195
139
- ``` git reset [commit] ```
140
- Undo all commits after [ commit] , preserving changes locally
141
196
142
- ``` git reset --hard [commit] ```
143
- Discard all history and changes back to the specified commit
197
+ ``` $ git reset [commit] ```
198
+
199
+ Undoes all commits after [ commit] , preserving changes locally
200
+
201
+
202
+ ``` $ git reset --hard [commit] ```
203
+
204
+ Discards all history and changes back to the specified commit
144
205
145
206
## Synchronize changes
146
207
Register a repository bookmark and exchange version history
147
208
148
- ``` git fetch [bookmark] ```
149
- Download all history from the repository bookmark
150
209
151
- ``` git merge [bookmark]/[branch] ```
152
- Combine bookmark’s branch into into current local branch
210
+ ``` $ git fetch [bookmark] ```
211
+
212
+ Downloads all history from the repository bookmark
213
+
214
+
215
+ ``` $ git merge [bookmark]/[branch] ```
216
+
217
+ Combines bookmark’s branch into current local branch
218
+
219
+
220
+ ``` $ git push [alias] [branch] ```
221
+
222
+ Uploads all local branch commits to GitHub
223
+
153
224
154
- ``` git push [alias] [branch] ```
155
- Upload all local branch commits to GitHub
225
+ ``` $ git pull ```
156
226
157
- ``` git pull ```
158
- Synchronize bookmark history and incorporate current branch changes
227
+ Synchronizes bookmark history and incorporates current branch changes
159
228
160
229
---
161
230
0 commit comments