-
Notifications
You must be signed in to change notification settings - Fork 348
/
Copy path8. Git Commands
926 lines (894 loc) · 20.3 KB
/
8. Git Commands
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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
1 git --version
2 ls -l
3 mkdir project1
4 cd project1/
5 ls -l
6 ls -la
7 git status
8 git init
9 ls -la
10 touch file1.java
11 vi file1.java
12 ls -l
13 ls -la
14 git ls-files
15 git status
16 git add file1.java
17 git status
18 git log
19 git ls-files
20 git commit -m "1st commit"
21 git config --global user.email "[email protected]"
22 git config --global user.name "Raushan Kumar"
23 git commit -m "1st commit"
24 git log
25 git log --one-line
26 git log --oneline
27 git status
28 ls -l
29 git ls-files
30 git status
31 history
----------------------------------------------
1 ls -l
2 cd project1/
3 ls -l
4 git status
5 ls -l
6 git ls-files
7 git status
8 clear
9 touch file2.java
10 vi file2.java
11 git status
12 ls -l
13 git add file2.java
14 git ls-files
15 git status
16 git log --oneline
17 git commit -m "2nd commit"
18 git config --list
19 git log --oneline
20 git status
21 git show 48ac98f
22 git remote -v
23 git remote add origin https://github.com/raushan8586/september-2023-repo.git
24 git remote -v
25 git branch
26 git push origin master
27 git fetch
28 git ls-files
29 git pull
30 git pull origin master
31 git ls-files
32 git remote add origin1 https://github.com/raushan8586/september-2023-repo2.git
33 git remote -v
34 history
---------------------------------------------------------------------------------
git branch
46 git log --oneline
47 git branch b1 master
48 git branch
49 git checkout b1
50 git branch
51 git log --oneline
52 vi b1_code1
53 ls -l
54 git status
55 git add .
56 git status
57 git commit -m "b1_1st-commit"
58 git log --oneline
59 git push origin b1
60 cd ..
61 ls -l
62 git clone https://github.com/raushan8586/september-2023-repo.git
63 ls -l
64 cd september-2023-repo/
65 ls -l
66 ls -la
67 git branch
68 git checkout b1
69 git branch
70 ls -l
71 cd ../project1/
72 git branch
73 git log --oneline
74 git checkout master --> Go to the destination branch
75 git merge b1 master --> feature branch (b1) has more commits than Master --> git merge src destination
76 git log --oneline
77 git log
78 git log --oneline
79 git pull origin master
80 history
-------------------------------------------------------------------------------
1 ls -l
2 cd project1/
3 ls -
4 ls -l
5 git log --oneline
6 git branch
7 git checkout -b b2 master
8 git branch
9 git checkout master
10 git log --oneline
11 git show 3dbea42
12 ls -l
13 vi file3.java
14 git status
15 ls -la
16 git add .
17 git status
18 git commit -m "3rd commit"
19 git status
20 vi file3.java
21 git status
22 git diff file3.java
23 git add file3.java
24 git diff file3.java
25 git diff --staged file3.java
26 ls -l
27 git commit -m "4th commit"
28 ls -l
29 rm file3.java
30 ls -l
31 git status
32 git restore file3.java
33 ls -l
34 git status
35 git rm file3.java
36 ls -l
37 git ls-files
38 git status
39 git restore --staged file3.java
40 git status
41 ls -l
42 git ls-files
43 git restore file3.java
44 ls -l
45 git status
------------------------------------------------------------------
git log --oneline
49 ls -l
50 vi app.log
51 vi ReadMe
52 vi my-notes
53 git status
54 vi file4.java
55 git status
56 git add file4.java
57 git status
58 git commit -m "5th commit"
59 git status
60 vi .gitignore
61 git status
62 git add .
63 git commit -m ".gitIgnoreAdded"
64 git status
65 vi my-notes
66 git status
67 git log --oneline
68 ls -l
69 vi file5.java
70 git add .
71 git commit -m "6th commit"
72 git log --oneline
73 git show 564730e
74 git revert 564730e
75 git log --oneline
76 ls -l
77 git show 7491b88
78 clear
79 git log --oneline
80 ls -l
81 git reset --hard 87eea67
82 git log --oneline
83 git status
Rebase --> When the feature branch needs to get updated (get all the commits) from Master
Go to the feature branch (b1)
git rebase master
merge -- additional commits from a feature branch to another feature branch --> syncing updates
rebase -- local master to feature branch --> syncing updates
Merge -->
git merge src destination
checkout to the destination
git merge b3 master
To avoid parallel development, perform rebase before merge. We should try to perform linear development
1 git log
2 cd project1/
3 got log
4 git log
5 git config --list
6 ls -l
7 git status
8 ls -la
9 cat .gitignore
10 git branch
11 git log --onelie
12 git log --oneline
13 git checkout b1
14 git rebase master
15 git log --oneline
16 git checkout b2
17 git branch
18 git rebase master
19 git log --oneline
20 git push origin master
21 git log --oneline
22 git push origin b1
23 git log --oneline
24 git push origin b2
25 git remote -v
26 git log --graph --pretty=oneline
27 git branch
28 git checkout master
29 git log --graph --pretty=oneline
30 git branch
31 git log --graph --pretty=oneline
32 ls -l
33 vi file5.java
34 git add .
35 git commit -m "6th commit"
36 git checkout b1
37 vi b1_code2
38 git add .
39 git commit -m "b1_2nd-commit"
40 git checkout master
41 git merge b1 master
42 git log --graph --pretty=oneline
43 git checkout b1
44 git log --graph --pretty=oneline
45 git rebase master
46 git log --graph --pretty=oneline
Conflict Scenario: --> Parallel Development + File Name same --> Needs to be resolved manually
48 git checkout master
49 vi test.java
50 git add .
51 git commit -m "test-file-added-master"
52 git log --graph --pretty=oneline
53 git checkout b1
54 vi test.java
55 git add .
56 git commit -m "test-file-added-b1"
57 git checkout master
58 git merge b1 master
59 ls -l
60 cat test.java
61 vi test.java
62 git status
63 git add .
64 git status
65 git commit -m "test.java-file-updated-conflict-fix"
66 git status
67 git log --graph --pretty=oneline
68 history
--------------------------------------------------------------------------------------------------------
1 cd project1/
2 ls -l
3 vi file4.java
4 vi file5.java
5 git branch
6 git status
7 git stash list --> list all the stash IDs
8 git stash --> move unstaged changes to the temp shell
9 git stash list
10 git log --oneline
11 git show stash@{0} --> describe the stash id
12 git status
13 git stash pop stash@{0} --> unstash and delete the stash id from the tem shell. ("apply" --> does not delete form the tem shell)
14 git status
15 git stash list
16 git stash -p --> used for partial stashing
17 git stash list
18 git show stash@{0}
19 git status
20 git stash drop stash@{0} --> delete the stash id
21 git stash list
22 git stash
23 git stash list
24 git stash drop stash@{0}
25 vi file4.java
26 git stash
27 vi file5.java
28 git stash
29 git stash list
30 git stash clear
31 git stash list
-------------------------------------------------------------
17th May --> git commands
root@ip-172-31-9-149:~/project1# history
1 apt update -y
2 clear
3 git --version
4 ls -l
5 pwd
6 git clone https://github.com/raushan8586/devops-2023-september.git
7 history
8 ls -l
9 cd devops-2023-september/
10 ls -l
11 ls
12 ls -l
13 ls -lrt
14 clear
15 ls -l
16 clear
17 git log --oneline
18 pwd
19 ls -l
20 clear
21 git log --oneline
22 ls -l
23 cd ..
24 clear
25 ls -l
26 mkdir project1
27 cd project1/
28 pwd
29 ls -la
30 cd ../devops-2023-september/
31 ls -la
32 cd ../project1/
33 clear
34 ls -la
35 git init
36 ls -la
37 touch sample1.txt
38 vi sample1.txt
39 car sample1.txt
40 clear
41 ls -l
42 cat sample1.txt
43 vi sample.java
44 cat sample.java
45 ls -l
46 ls -la
47 git status
48 cd ..
49 mkdir project2
50 cd project2
51 vi demo.txt
52 cat demo.txt
53 git status
54 cd ../project1/
55 clear
56 git status
57 pwd
58 git status
59 git log --oneline
60 git add sample.java sample1.txt
61 ls -l
62 clear'
63 clear
64 git status
65 git commit -m "1st-commit"
66 git log --oneline
67 git log
68 git remote -v
69 git remote add origin https://github.com/raushan8586/repo-demo.git
70 clear
71 git remote -v
72 git status
73 git push origin master
74 clear
75 ls -l
76 vi demo.java
77 cat demo.java
78 git status
79 ls -l
80 git add demo.java
81 git status
82 ls -l
83 git ls-files
84 git commit -m "2nd-commit"
85 git status
86 ls -l
87 git ls-files
88 clear
89 ls -l
90 git ls-files
91 git status
92 git remote -v
93 git push origin master
96 git config --global user.email "[email protected]"
97 git config --global user.name "Raushan Kumar"
----------------------------------------------------------------------------------------------
21st May 2024
138 git status
139 git branch b1 master
140 git branch
141 git log --oneline
142 git show 107fd7b
143 git checkout b1
144 git branch
143 git checkout b1
144 git branch
145 git log --oneline
146 git push origin b1
----------------------------------------------------------------------------------------------------------
22nd May 2024
git branch
169 git checkout -b b2 master
170 git branch
171 git log --oneline
172 git checkout master
173 git log --oneline
174 git branch
175 ls -l
176 git pull origin master
177 git log --oneline
178 git checkout b2
179 git rebase master
180 git log --oneline
181 git checkout b2
182 vi b2_file1.java
183 git add .
184 git commit -m "b2_1st-commit"
185 git push origin b2
186 git branch
187 git checkout -b b3 master
188 git log --oneline
189 git checkout b2
190 git log --oneline
191 git checkout b3
192 git merge b2 b3
193 git log --oneline
194 git branch
195 git log --oneline
196 vi app1.log
197 vi readMe
198 ls -l
199 git status
200 vi sample6.html
201 git status
202 git add sample6.html
203 git status
204 git commit -m "sample6.java-commit"
205 git status
206 vi .gitignore
207 git status
208 git add .gitignore
209 git commit -m "git-ignore-file-added"
210 git status
211 ls -l
212 git log --oneline
213 vi sample7.java
214 git add .
215 git commit -m "sample7.java-added"
216 git log --oneline
217 git show 445f58c
218 git revert 445f58c
219 git log --oneline
220 ls -l
221 git show 480e521
--------------------------------------------
23rd May
----------
git log --oneline
230 ls -l
231 rm sample6.html
232 ls -l
233 git status
234 git restore sample6.html
235 git status
236 ls -l
237 git rm sample6.html
238 ls -l
239 git ls-files
240 git status
241 git restore --staged sample6.html
242 git ls-files
243 git status
244 git restore sample6.html
245 git status
246 ls -l
247 git log --oneline
248 git reset --soft b1e5fe6
249 git log --oneline
250 git status
251 ls -l
252 git ls-files
253 vi rock-demo.java
254 git add .
255 git commit -m "rock-demo.java added"
256 clear
257 ls -l
258 git log --oneline
259 git reset --soft b1e5fe6
260 git log --oneline
261 ls -l
262 git status
263*
264 git status
265 git add .
266 git status
267 git commit -m "rock-demo.java added again"
268 git log --oneline
269 git reset --hard b1e5fe6
270 git status
271 ls -l
272 git ls-files
273 git log --oneline
274 clear
275 git log --graph --pretty=oneline
276 git branch
277 git log --oneline
278 git checkout master
279 git log --oneline
280 git merge b3 master
281 git log --oneline
282 git remote -v
283 git pull origin master
284 git log --graph --pretty=oneline
285 git remote -v
286 git branch
287 git log --oneline
288 git checkout -b b4 master
289 git log --oneline
290 vi test.java
291 git add .
292 git commit -m "b4-1st-commit"
293 git checkout b3
294 vi test.java
295 git add .
296 git commit -m "b3-commit-test.java"
297 git merge b4 b3
298 git status
299 vi test.java
300 git status
301 git add .
302 git status
303 git commit -m "merge-conflict-resolved"
304 git status
305 git log --graph -- pretty=oneline
306 git log --graph --pretty=oneline
307 git log
-----------------------------------------------
24th May
314 vi code1-file.java
315 vi code2-file.java
316 git status
317 ls -l
318 git branch
319 git checkout b2
320 git status
321 git checkout b3
322 git status
323 ls -l
324 git add .
325 git commit -m "code-files-added"
326 git status
327 vi code1-file.java
328 vi code2-file.java
329 git status
330 git stash list
331 git stash
332 git status
333 git stash list
334 git show stash@{0}
335 git stash pop stash@{0}
336 git status
337 git stash -p
338 git status
339 git stash list
340 git show stash@{0}
341 git add .
342 git commit -m "code2-file.java"
343 git status
344 git stash list
345 git stash clear
346 git stash list
347 vi code1-file.java
348 git stash list
349 git status
350 git stash
351 git stash list
352 vi code2-file.java
353 git status
354 git stash
355 git stash list
356 git stash drop stash@{1}
357 git stash list
------------------------------------------------------
devops-nov-2024
-------------------------------------------------------
1 apt update -y
2 git version
3 ls -l
4 git clone https://github.com/raushan8586/devops-19nov-2024.git
5 ls -l
6 cd devops-19nov-2024/
7 ls -l
8 git branch
9 cd ..
10 ls -l
11 cd devops-19nov-2024/
12 ls -l
13 ls -la
14 ls -l
15 cd ..
16 ls -l
17 mkdir project1
18 cd project1/
19 ls -la
20 git init
21 ls -la
22 git branch
23 ls -la
24 cd ..
25 mkdir project2
26 ls -l
27 cd project1
28 ls -l
29 ls -la
30 vi file1
31 cat file1
32 ls -l
33 pwd
34 git status
35 cd ../project2/
36 vi file1
37 ls -l
38 ls -la
39 git status
40 cd ../project1/
41 git status
42 ls -l
43 git add file1
44 git status
45 git log
46 git commit -m "1st commit"
47 git status
48 ls -l
49 git ls-files
50 git log
51 vi file2
52 ls -l
53 git ls-files
54 git status
55 git add file2
56 git status
57 git commit -m "2nd-commit"
58 git status
59 git ls-files
60 git log
61 ls -l
62 cd project
63 cd project1/
64 ls -l
65 ls -la
66 vi file3
67 ls -l
68 git ls-files
69 git status
70 git add file3
71 git status
72 git commit -m "3rd commit"
73 git log
74 git config --global user.email "[email protected]"
75 git config --global user.name "Raushan Kumar"
76 vi file4
77 vi file5
78 git status
79 git add .
80 git commit -m "4th commit"
81 git log
82 git branch
83 git status
84 git log --one-line
85 git log -oneline
86 git log --oneline
87 git show dd1b59b
88 git remote -v
89 cd ..
90 ls -l
91 cd devops-19nov-2024/
92 git remote -v
93 cd ../project1/
94 ls -l
95 git remote -v
96 git status
97 git remote add origin https://github.com/raushan8586/devops-nov-2024.git
98 git remote -v
99 git push origin master
100 git log --oneline
102 git branch
103 ls -l
104 cd project
105 cd project1/
106 ls -l
107 git log --oneline
108 git status
109 git branch
110 git remote -v
111 git log --oneline
112 git pull
113 git log --oneline
114 git pull origin master
115 git log --oneline
116 git branch b1 master
117 git branch
118 git checkout b1
119 git branch
120 vi feature1
121 git add .
122 git commit -m "feature1-d1-commit"
123 git log --oneline
124 git remote -v
125 git push origin b1
126 git branch
127 git log --oneline
128 git checkout master
129 git pull origin master
130 git log --oneline
131 git branch
132 git pull origin master
133 git log --oneline
134 git checkout b1
135 git log --oneline
136 git rebase master
137 git log --oneline
138 git branch
139 git checkout -b b2 master
140 git branch
141 git log --oneline
142 ls -l
143 vi app1.log
144 vi ReadMe
145 vi feature3
146 git status
147 vi .gitignore
148 git status
149 git add .
150 git commit -m "feature3-gitignore-file-added"
151 git status
152 ls -l
153 git ls-files
154 git push origin b2
155 vi feature4
156 git add .
157 git commit -m "feature4 added"
158 git log --oneline
159 git show acc64ae
160 git revert acc64ae
161 git log --oneline
162 git show 530fcf8
163 git log --oneline
164 ls -l
165 git revert 530fcf8
166 git log --oneline
167 ls -l
168 rm file1
169 ls -l
170 git status
171 git restore file1
172 ls -l
ls -l
175 cd project1
176 ls -l
177 pwd
178 ls -la
179 git status
180 git branch
181 git log --oneline
182 ls -l
183 vi feature5
184 ls -l
185 cd project1/
186 pwd
187 ls -l
188 git status
189 vi feature5
190 git add .
191 git commit -m "feature5 added"
192 git log --oneline
193 ls -l
194 git ls-files
195 git status
196 ls -l
197 git log --oneline
198 rm feature5
199 ls -l
200 git status
201 git ls-files
202 git restore feature5
203 ls -l
204 git status
205 git log --oneline
206 git revert 9ecbac6
207 git log --oneline
208 ls -l
209 git ls-files
210 git log --oneline
211 git checkout master
212 git log --oneline
213 git checkout b1
214 git log --oneline
215 git checkout b2
216 git log --oneline
217 git reset --hard acc64ae
218 git log --oneline
219 git status
220 ls -l
221 git log --oneline
222 vi feature5
223 git add .
224 git commit -m "feature5 added"
225 vi feature4
226 vi feature5
227 git status
228 ls -l
229 git status
230 git stash list
231 git stash
232 git status
233 git stash list
234 git show stash@{0}
235 git stash list
236 git status
237 git stash list
238 git stash pop stash@{0}
239 git status
240 git stash list
241 git stash -p
242 git status
243 vi feature4
244 git add .
245 git commit -m "feature4 completed"
246 git status
247 git stash list
248 git show stash@{0}
249 git stash drop stash@{0}
250 git stash list
251 ls -l
252 cat feature5
253 ls -l
254 git status
255 rm feature5
256 git status
257 git restore feature5
258 git status
259 git rm feature5
260 ls -l
261 git ls-files
262 git status
263 git rstore --staged feature5
264 git status
265 git restore --staged feature5
266 git status
267 git ls-files
268 ls -l
269 git restore feature5
270 git status
271 ls -l
272 cd project1
273 ls -l
274 git branch
275 git checkout master
276 ls -l
277 git log --oneline
278 git checkout -b b3 master
279 git log --oneline
280 git checkout master
281 vi test
282 git add .
283 git commit -m "d1-test-file"
284 git checkout b3
285 vi test
286 git add .
287 git commit -m "d3-test-file"
288 git rebase master
289 git branch
290 ls -l
291 cat test
292 git status
293 vi test
294 git status
295 git add test
296 git status
297 git commit -m "merge-conflict-resolved"
298 git status
299 git rebase --continue
300 git status
301 git log --oneline
302 ls -l