-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGit Tutorial
More file actions
334 lines (184 loc) · 4.65 KB
/
Copy pathGit Tutorial
File metadata and controls
334 lines (184 loc) · 4.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
-- Git Config
git config --global user.name "Your Name"
git config --global user.email "Your Email"
-- Locla Git States
- Working Directory
- Staging Area
- Repository (.git)
- Remote Repo.
-- Create README.md File
touch README.md
-- Check Git Status
git status
-- Add Files In Staging Area
git add .
git add --all
git add -A
git add filename.ext
-- Commit Command
git commit
git commit -m "Your Message"
-- Remove Files
cd ..
rm -rf .git
-- List All Files
ls -a
-- Commit Detail's
git log
git log --oneline
git log --oneline --graph
git show
-- Commit Express
git commit -a
git commit -am "Your Message"
-- Backing Out Changes
/ * Unstaged Changes after reset */
git reset HEAD filename.ext
/ * Discard The Changes In Working Directory */
git checkout -- filename.ext
-- History and Making New Commands With Alias
git help log
git log --oneline --graph --decorate --all
git config --global alias.hist "log --oneline --graph --decorate --all"
git config --global --list
git hist
git hist -- filename.ext
-- Rename and Delete Files
git rm filename.ext
-- Managing Files Outside Of Git
touch filename.ext
ls -a
mv filename.ext newname.ext
ls -l
rm filename.ext
git add -u
-- Comparing Differences
git config --global alias.hist "log --oneline --graph --decorate --all"
git hist
/* Commit History */
* 5a05d32 (HEAD -> master) New Updates
* 076f8a0 New
* 6f30ed0 deleting demo file
* 7aefe16 Demo File Added
* 09aac84 Renaming Command
* bda83a4 Commit Express
* 8353e28 New Commit
* cdd5ed6 First file in demo repo
/* Here cdd5ed6 is commit id in Commit History & HEAD is latest commit id */
git diff cdd5ed6 HEAD
/*
Branching & Merge Types
Branch = Timeline Of Commits
Branch Names are Labels
- Deletion Removes Labels Only
*/
-- Types Of Merges
* Fast-Forward
- Simplest Case
- Like Never Branched (Commits On Destination)
- Can Be Disabled
* Automatic
- Non-Conflicting Merge Detected
- Preserves both Timelines
- Merge Commit on Destination
* Manual
- Automatic Merge Not Possible
- Conflicting Merge State
- Changes Saved in Merge Commit
-- Special Markers
* HEAD - Last Commit
- Points to Last Commit of Current Branch
- Can be Moved (Advanced)
-- Simple Branching Example
/* List of Branches */
git branch
/* Create New Branch */
git branch branch-name
/* Switch Branch */
git checkout branch-name
/* Create & Switch Branch */
git checkout -b branch-name
/* Merge Branch */
git merge branch-name
/* Delete Branch */
git branch -d branch-name
-- Conflict Resolution
-- Marking Special Events With Tagging
/* Create New Tag */
git tag tag-name
git tag -a v1.0 -m "Commit Message"
/* Tag List */
git tag --list
/* Delete Tag */
git tag -d tag-name
-- Saving Work In Progress With Stashing
git stash
git stash list
git stash pop
git stash apply stash{index}
-- Time Travel With Reset & Reflog
git reset commit-id --soft
git reset commit-id --mixed
git reset commit-id --hard
git reflog
git reset --hard head-id
git reset --mixed head-id
git reset --soft head-id
-- Remote Repository Commands
/* After Commit */
git push
/* If Any File Changed In Github */
git fetch
git pull
git push
/* Check version remote repository */
git remote -v
/*
origin git@github.com:Prafulm8o6/website.git (fetch)
origin git@github.com:Prafulm8o6/website.git (push)
*/
git remote show origin
/* Rename the local repository */
git remote set-url git@github.com:Prafulm8o6/website.git
/* Check Details Of */
git remote show origin
/*
* remote origin
Fetch URL: git@github.com:Prafulm8o6/website.git
Push URL: git@github.com:Prafulm8o6/website.git
HEAD branch: main
Remote branch:
main tracked
Local branch configured for 'git pull':
main merges with remote main
Local ref configured for 'git push':
main pushes to main (up to date)
*/
-- Local Remote Repo.
git push -u origin branch-name
/* List all remotes/origin/branch */
git branch -a
/* delete the remotes/origin/branch */
git branch -d branch-name
/* remove the reference of deleted remotes/origin/branch */
git fetch -p
-- tag
/* List the tags */
git tag
/* Create new tag */
git tag tag-name origin-branch-name
/* Create -a tags */
git tag -a tag-name -m "Your Message" commit-id
Ex:- git tag -a v0.1-alpha -m "Release 0.1 (Alpha)" commit-id
/* push tag on github repository */
git push origin tag-name
/* Delete tag from local repo. */
git tag -d tag-name
/* Delete repository ta from local repo. */
git push origin :tag-name
/* push all tag to github repo. */
git push --tags
/* Updating tags creating a floating tag */
git tag -f tag-name commit-id
/* Push Updated tag */
git push --force origin tag-name