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