You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### Remote synchronization from Repository(Repository --> Remote)
95
95
96
-
# Push the current branch to the Remote Repository.
97
-
$ git push origin [branch]
96
+
# Push the current branch to the Remote Repository.
97
+
$ git push origin [branch]
98
98
99
99
100
100
### Repository synchronization from remote (Repository <-- Remote)
101
101
102
-
# Download specific branch.
103
-
$ git fetch origin [branch]
102
+
# Download specific branch.
103
+
$ git fetch origin [branch]
104
104
105
-
# Download all remote branches.
106
-
$ git fetch --all
105
+
# Download all remote branches.
106
+
$ git fetch --all
107
107
108
108
109
109
### Workspace synchronization from Repository (Workspace <-- Repository)
110
110
111
-
# merge the specified branch to the current branch.
112
-
$ git merge [branch]
111
+
# merge the specified branch to the current branch.
112
+
$ git merge [branch]
113
113
114
-
# merge a branch into a target branch
115
-
$ git merge [source branch] [target branch]
114
+
# merge a branch into a target branch
115
+
$ git merge [source branch] [target branch]
116
116
117
117
118
118
### Workspace synchronization from remote (Workspace <-- Repository <-- Remote)
119
119
120
-
# Retrieve the changes to the Remote Repository and merge with the local branch (fetch+merge)
121
-
$ git pull origin [branch]
122
-
120
+
# Retrieve the changes to the Remote Repository and merge with the local branch (fetch+merge)
121
+
$ git pull origin [branch]
122
+
123
123
124
124
### Branching
125
125
126
-
# List all local branches. (the asterisk denotes the current branch)
127
-
$ git branch
126
+
# List all local branches. (the asterisk denotes the current branch)
127
+
$ git branch
128
128
129
-
# List all remote branches.
130
-
$ git branch -r
129
+
# List all remote branches.
130
+
$ git branch -r
131
131
132
-
# List all local branches and remote branches.
133
-
$ git branch -a
132
+
# List all local branches and remote branches.
133
+
$ git branch -a
134
134
135
-
# Create a new branch, but still stay in the current branch.
136
-
$ git branch [branch-name]
135
+
# Create a new branch, but still stay in the current branch.
136
+
$ git branch [branch-name]
137
137
138
-
# Create a new branch and switch to the branch.
139
-
$ git checkout -b [branch]
138
+
# Create a new branch and switch to the branch.
139
+
$ git checkout -b [branch]
140
140
141
-
# Switch to the specified branch and update the workspace.
142
-
$ git checkout [branch-name]
141
+
# Switch to the specified branch and update the workspace.
142
+
$ git checkout [branch-name]
143
143
144
-
# Switch to the previous branch.
145
-
$ git checkout -
144
+
# Switch to the previous branch.
145
+
$ git checkout -
146
146
147
-
# Delete the branch.
148
-
$ git branch -d [branch-name]
147
+
# Delete the branch.
148
+
$ git branch -d [branch-name]
149
149
150
-
# Delete the remote branch.
151
-
$ git push origin --delete [branch-name]
152
-
$ git branch -dr [remote/branch]
150
+
# Delete the remote branch.
151
+
$ git push origin --delete [branch-name]
152
+
$ git branch -dr [remote/branch]
153
153
154
154
155
155
### Inspection
156
156
157
-
# Display the changed files.
158
-
$ git status
157
+
# Display the changed files.
158
+
$ git status
159
159
160
-
# Display the version history of the current branch.
161
-
$ git log
160
+
# Display the version history of the current branch.
161
+
$ git log
162
162
163
-
# Display all commits (Custom Filtering)
164
-
$ git log --all
163
+
# Display all commits (Custom Filtering)
164
+
$ git log --all
165
165
166
-
# Display the 5 most recent commits (Custom Filtering)
167
-
$ git log -5
166
+
# Display the 5 most recent commits (Custom Filtering)
167
+
$ git log -5
168
168
169
-
# View Commit History in ASCII Graph
170
-
$ git log --graph
171
-
172
-
# Display Just One Line Per Commit
173
-
$ git log --oneline
169
+
# View Commit History in ASCII Graph
170
+
$ git log --graph
171
+
172
+
# Display Just One Line Per Commit
173
+
$ git log --oneline
174
174
175
-
# Display Just One Line Per Commit with message (Custom Formatting)
176
-
$ git log --pretty=oneline
175
+
# Display Just One Line Per Commit with message (Custom Formatting)
176
+
$ git log --pretty=oneline
177
177
178
-
# Display all the users who have committed, sorted by number of commits.
179
-
$ git shortlog -sn
178
+
# Display all the users who have committed, sorted by number of commits.
179
+
$ git shortlog -sn
180
180
181
-
# Show the latest commits of the current branch.
182
-
$ git reflog
181
+
# Show the latest commits of the current branch.
182
+
$ git reflog
183
183
184
184
For more details:
185
185
@@ -191,86 +191,86 @@ Though there are 1000’s of articles about git, I have written this article is
191
191
192
192
### Revoke
193
193
194
-
# Restore the specified file of the Staging to the Workspace.
195
-
$ git checkout [file]
194
+
# Restore the specified file of the Staging to the Workspace.
195
+
$ git checkout [file]
196
196
197
-
# Restore the specified file of a certain commit to the Staging and Workspace.
198
-
$ git checkout [commit] [file]
197
+
# Restore the specified file of a certain commit to the Staging and Workspace.
198
+
$ git checkout [commit] [file]
199
199
200
-
# Restore all the files in the Staging to the Workspace.
201
-
$ git checkout .
200
+
# Restore all the files in the Staging to the Workspace.
201
+
$ git checkout .
202
202
203
-
# Reset the specified file in the Staging, keeping consistent with the previous commit, but remaining the workspace unchanged.
204
-
$ git reset [file]
203
+
# Reset the specified file in the Staging, keeping consistent with the previous commit, but remaining the workspace unchanged.
204
+
$ git reset [file]
205
205
206
-
# Reset the Staging and workspace, keeping consistent with the last commit.
207
-
$ git reset --hard
206
+
# Reset the Staging and workspace, keeping consistent with the last commit.
207
+
$ git reset --hard
208
208
209
-
# Reset the pointer of the current branch to pointing the specified commit while resetting the Staging, but the workspace remains unchanged.
210
-
$ git reset [commit]
209
+
# Reset the pointer of the current branch to pointing the specified commit while resetting the Staging, but the workspace remains unchanged.
210
+
$ git reset [commit]
211
211
212
-
# Reset the HEAD of the current branch to the specified commit while resetting the Staging and Workspace, keeping consistent with the specified commit.
213
-
$ git reset --hard [commit]
212
+
# Reset the HEAD of the current branch to the specified commit while resetting the Staging and Workspace, keeping consistent with the specified commit.
213
+
$ git reset --hard [commit]
214
214
215
-
# Reset the current HEAD to the specified commit, remaining the Staging and Workspace unchanged.
216
-
$ git reset --keep [commit]
215
+
# Reset the current HEAD to the specified commit, remaining the Staging and Workspace unchanged.
216
+
$ git reset --keep [commit]
217
217
218
-
# Create a new commit to undo the specified commit.
219
-
# All changes of the latter will be offset by the former and applied to the current branch.
220
-
$ git revert [commit]
218
+
# Create a new commit to undo the specified commit.
219
+
# All changes of the latter will be offset by the former and applied to the current branch.
220
+
$ git revert [commit]
221
221
222
-
# Remove the uncommitted changes temporarily and move them in later.
223
-
$ git stash
224
-
$ git stash pop
222
+
# Remove the uncommitted changes temporarily and move them in later.
223
+
$ git stash
224
+
$ git stash pop
225
225
226
226
227
227
### Ignore files and folder
228
228
229
-
# Delete the files in the Workspace and put this deletion into the Staging.
230
-
$ git rm [file1] [file2] ...
229
+
# Delete the files in the Workspace and put this deletion into the Staging.
230
+
$ git rm [file1] [file2] ...
231
231
232
-
# Stop tracking the specified file, but the file will be remained in the Workspace.
233
-
$ git rm --cached [file]
232
+
# Stop tracking the specified file, but the file will be remained in the Workspace.
233
+
$ git rm --cached [file]
234
234
235
235
236
236
### Tag
237
237
238
-
# List all tags.
239
-
$ git tag
238
+
# List all tags.
239
+
$ git tag
240
240
241
-
# Create a new tag in the current commit.
242
-
$ git tag [tag]
241
+
# Create a new tag in the current commit.
242
+
$ git tag [tag]
243
243
244
-
# Create a new tag in the specified commit.
245
-
$ git tag [tag] [commit]
244
+
# Create a new tag in the specified commit.
245
+
$ git tag [tag] [commit]
246
246
247
-
# Delete the local tag.
248
-
$ git tag -d [tag]
247
+
# Delete the local tag.
248
+
$ git tag -d [tag]
249
249
250
-
# Delete the remote tag.
251
-
$ git push origin :refs/tags/[tagName]
250
+
# Delete the remote tag.
251
+
$ git push origin :refs/tags/[tagName]
252
252
253
-
# View the tag information.
254
-
$ git show [tag]
253
+
# View the tag information.
254
+
$ git show [tag]
255
255
256
-
# Commit the specified tag.
257
-
$ git push [remote] [tag]
256
+
# Commit the specified tag.
257
+
$ git push [remote] [tag]
258
258
259
-
# Commit all tags.
260
-
$ git push [remote] --tags
259
+
# Commit all tags.
260
+
$ git push [remote] --tags
261
261
262
-
# Create a new branch pointing to a certain tag
263
-
$ git checkout -b [branch] [tag]
262
+
# Create a new branch pointing to a certain tag
263
+
$ git checkout -b [branch] [tag]
264
264
265
265
266
266
267
267
### Others
268
268
269
-
# Select a commit to be merged into the current branch.
270
-
$ git cherry-pick [commit]
269
+
# Select a commit to be merged into the current branch.
0 commit comments