forked from seankross/the-unix-workbench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-and-github.html
1112 lines (1042 loc) · 97.9 KB
/
git-and-github.html
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
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>The Unix Workbench</title>
<meta name="description" content="The Unix Workbench">
<meta name="generator" content="bookdown 0.6 and GitBook 2.6.7">
<meta property="og:title" content="The Unix Workbench" />
<meta property="og:type" content="book" />
<meta property="og:url" content="https://github.com/seankross/the-unix-workbench" />
<meta property="og:image" content="https://github.com/seankross/the-unix-workbenchimages/cover.png" />
<meta name="github-repo" content="seankross/the-unix-workbench" />
<meta name="twitter:card" content="summary" />
<meta name="twitter:title" content="The Unix Workbench" />
<meta name="twitter:image" content="https://github.com/seankross/the-unix-workbenchimages/cover.png" />
<meta name="author" content="Sean Kross">
<meta name="date" content="2018-03-21">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="prev" href="bash-programming.html">
<link rel="next" href="nephology.html">
<script src="libs/jquery-2.2.3/jquery.min.js"></script>
<link href="libs/gitbook-2.6.7/css/style.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-bookdown.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-highlight.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-search.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-fontsettings.css" rel="stylesheet" />
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-47412721-2"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-47412721-2');
</script>
<style type="text/css">
div.sourceCode { overflow-x: auto; }
table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode {
margin: 0; padding: 0; vertical-align: baseline; border: none; }
table.sourceCode { width: 100%; line-height: 100%; }
td.lineNumbers { text-align: right; padding-right: 4px; padding-left: 4px; color: #aaaaaa; border-right: 1px solid #aaaaaa; }
td.sourceCode { padding-left: 5px; }
code > span.kw { color: #007020; font-weight: bold; } /* Keyword */
code > span.dt { color: #902000; } /* DataType */
code > span.dv { color: #40a070; } /* DecVal */
code > span.bn { color: #40a070; } /* BaseN */
code > span.fl { color: #40a070; } /* Float */
code > span.ch { color: #4070a0; } /* Char */
code > span.st { color: #4070a0; } /* String */
code > span.co { color: #60a0b0; font-style: italic; } /* Comment */
code > span.ot { color: #007020; } /* Other */
code > span.al { color: #ff0000; font-weight: bold; } /* Alert */
code > span.fu { color: #06287e; } /* Function */
code > span.er { color: #ff0000; font-weight: bold; } /* Error */
code > span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
code > span.cn { color: #880000; } /* Constant */
code > span.sc { color: #4070a0; } /* SpecialChar */
code > span.vs { color: #4070a0; } /* VerbatimString */
code > span.ss { color: #bb6688; } /* SpecialString */
code > span.im { } /* Import */
code > span.va { color: #19177c; } /* Variable */
code > span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code > span.op { color: #666666; } /* Operator */
code > span.bu { } /* BuiltIn */
code > span.ex { } /* Extension */
code > span.pp { color: #bc7a00; } /* Preprocessor */
code > span.at { color: #7d9029; } /* Attribute */
code > span.do { color: #ba2121; font-style: italic; } /* Documentation */
code > span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code > span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
</style>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div class="book without-animation with-summary font-size-2 font-family-1" data-basepath=".">
<div class="book-summary">
<nav role="navigation">
<ul class="summary">
<li><a href="./">The Unix Workbench</a></li>
<li class="divider"></li>
<li class="chapter" data-level="" data-path="index.html"><a href="index.html"><i class="fa fa-check"></i>Title Page</a></li>
<li class="chapter" data-level="" data-path="dedication.html"><a href="dedication.html"><i class="fa fa-check"></i>Dedication</a></li>
<li class="chapter" data-level="" data-path="acknowledgements.html"><a href="acknowledgements.html"><i class="fa fa-check"></i>Acknowledgements</a></li>
<li class="chapter" data-level="" data-path="introduction.html"><a href="introduction.html"><i class="fa fa-check"></i>Introduction</a></li>
<li class="chapter" data-level="1" data-path="what-is-unix.html"><a href="what-is-unix.html"><i class="fa fa-check"></i><b>1</b> What is Unix?</a></li>
<li class="chapter" data-level="2" data-path="getting-unix.html"><a href="getting-unix.html"><i class="fa fa-check"></i><b>2</b> Getting Unix</a><ul>
<li class="chapter" data-level="2.1" data-path="getting-unix.html"><a href="getting-unix.html#mac-ubuntu-users"><i class="fa fa-check"></i><b>2.1</b> Mac & Ubuntu Users</a></li>
<li class="chapter" data-level="2.2" data-path="getting-unix.html"><a href="getting-unix.html#windows"><i class="fa fa-check"></i><b>2.2</b> Windows</a></li>
</ul></li>
<li class="chapter" data-level="3" data-path="command-line-basics.html"><a href="command-line-basics.html"><i class="fa fa-check"></i><b>3</b> Command Line Basics</a><ul>
<li class="chapter" data-level="3.1" data-path="command-line-basics.html"><a href="command-line-basics.html#hello-terminal"><i class="fa fa-check"></i><b>3.1</b> Hello Terminal!</a><ul>
<li class="chapter" data-level="3.1.1" data-path="command-line-basics.html"><a href="command-line-basics.html#summary"><i class="fa fa-check"></i><b>3.1.1</b> Summary</a></li>
<li class="chapter" data-level="3.1.2" data-path="command-line-basics.html"><a href="command-line-basics.html#exercises"><i class="fa fa-check"></i><b>3.1.2</b> Exercises</a></li>
</ul></li>
<li class="chapter" data-level="3.2" data-path="command-line-basics.html"><a href="command-line-basics.html#navigating-the-command-line"><i class="fa fa-check"></i><b>3.2</b> Navigating the Command Line</a><ul>
<li class="chapter" data-level="3.2.1" data-path="command-line-basics.html"><a href="command-line-basics.html#summary-1"><i class="fa fa-check"></i><b>3.2.1</b> Summary</a></li>
<li class="chapter" data-level="3.2.2" data-path="command-line-basics.html"><a href="command-line-basics.html#exercises-1"><i class="fa fa-check"></i><b>3.2.2</b> Exercises</a></li>
</ul></li>
<li class="chapter" data-level="3.3" data-path="command-line-basics.html"><a href="command-line-basics.html#creation-and-inspection"><i class="fa fa-check"></i><b>3.3</b> Creation and Inspection</a><ul>
<li class="chapter" data-level="3.3.1" data-path="command-line-basics.html"><a href="command-line-basics.html#summary-2"><i class="fa fa-check"></i><b>3.3.1</b> Summary</a></li>
<li class="chapter" data-level="3.3.2" data-path="command-line-basics.html"><a href="command-line-basics.html#exercises-2"><i class="fa fa-check"></i><b>3.3.2</b> Exercises</a></li>
</ul></li>
<li class="chapter" data-level="3.4" data-path="command-line-basics.html"><a href="command-line-basics.html#migration-and-destruction"><i class="fa fa-check"></i><b>3.4</b> Migration and Destruction</a><ul>
<li class="chapter" data-level="3.4.1" data-path="command-line-basics.html"><a href="command-line-basics.html#summary-3"><i class="fa fa-check"></i><b>3.4.1</b> Summary</a></li>
<li class="chapter" data-level="3.4.2" data-path="command-line-basics.html"><a href="command-line-basics.html#exercises-3"><i class="fa fa-check"></i><b>3.4.2</b> Exercises</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="4" data-path="working-with-unix.html"><a href="working-with-unix.html"><i class="fa fa-check"></i><b>4</b> Working with Unix</a><ul>
<li class="chapter" data-level="4.1" data-path="working-with-unix.html"><a href="working-with-unix.html#self-help"><i class="fa fa-check"></i><b>4.1</b> Self-Help</a><ul>
<li class="chapter" data-level="4.1.1" data-path="working-with-unix.html"><a href="working-with-unix.html#summary-4"><i class="fa fa-check"></i><b>4.1.1</b> Summary</a></li>
<li class="chapter" data-level="4.1.2" data-path="working-with-unix.html"><a href="working-with-unix.html#exercises-4"><i class="fa fa-check"></i><b>4.1.2</b> Exercises</a></li>
</ul></li>
<li class="chapter" data-level="4.2" data-path="working-with-unix.html"><a href="working-with-unix.html#get-wild"><i class="fa fa-check"></i><b>4.2</b> Get Wild</a><ul>
<li class="chapter" data-level="4.2.1" data-path="working-with-unix.html"><a href="working-with-unix.html#summary-5"><i class="fa fa-check"></i><b>4.2.1</b> Summary</a></li>
<li class="chapter" data-level="4.2.2" data-path="working-with-unix.html"><a href="working-with-unix.html#exercises-5"><i class="fa fa-check"></i><b>4.2.2</b> Exercises</a></li>
</ul></li>
<li class="chapter" data-level="4.3" data-path="working-with-unix.html"><a href="working-with-unix.html#search"><i class="fa fa-check"></i><b>4.3</b> Search</a><ul>
<li class="chapter" data-level="4.3.1" data-path="working-with-unix.html"><a href="working-with-unix.html#regular-expressions"><i class="fa fa-check"></i><b>4.3.1</b> Regular Expressions</a></li>
<li class="chapter" data-level="4.3.2" data-path="working-with-unix.html"><a href="working-with-unix.html#metacharacters"><i class="fa fa-check"></i><b>4.3.2</b> Metacharacters</a></li>
<li class="chapter" data-level="4.3.3" data-path="working-with-unix.html"><a href="working-with-unix.html#character-sets"><i class="fa fa-check"></i><b>4.3.3</b> Character Sets</a></li>
<li class="chapter" data-level="4.3.4" data-path="working-with-unix.html"><a href="working-with-unix.html#escaping-anchors-odds-and-ends"><i class="fa fa-check"></i><b>4.3.4</b> Escaping, Anchors, Odds, and Ends</a></li>
<li class="chapter" data-level="4.3.5" data-path="working-with-unix.html"><a href="working-with-unix.html#find"><i class="fa fa-check"></i><b>4.3.5</b> <code>find</code></a></li>
<li class="chapter" data-level="4.3.6" data-path="working-with-unix.html"><a href="working-with-unix.html#summary-6"><i class="fa fa-check"></i><b>4.3.6</b> Summary</a></li>
<li class="chapter" data-level="4.3.7" data-path="working-with-unix.html"><a href="working-with-unix.html#exercises-6"><i class="fa fa-check"></i><b>4.3.7</b> Exercises</a></li>
</ul></li>
<li class="chapter" data-level="4.4" data-path="working-with-unix.html"><a href="working-with-unix.html#configure"><i class="fa fa-check"></i><b>4.4</b> Configure</a><ul>
<li class="chapter" data-level="4.4.1" data-path="working-with-unix.html"><a href="working-with-unix.html#history"><i class="fa fa-check"></i><b>4.4.1</b> History</a></li>
<li class="chapter" data-level="4.4.2" data-path="working-with-unix.html"><a href="working-with-unix.html#customizing-bash"><i class="fa fa-check"></i><b>4.4.2</b> Customizing Bash</a></li>
<li class="chapter" data-level="4.4.3" data-path="working-with-unix.html"><a href="working-with-unix.html#summary-7"><i class="fa fa-check"></i><b>4.4.3</b> Summary</a></li>
</ul></li>
<li class="chapter" data-level="4.5" data-path="working-with-unix.html"><a href="working-with-unix.html#differentiate"><i class="fa fa-check"></i><b>4.5</b> Differentiate</a><ul>
<li class="chapter" data-level="4.5.1" data-path="working-with-unix.html"><a href="working-with-unix.html#summary-8"><i class="fa fa-check"></i><b>4.5.1</b> Summary</a></li>
</ul></li>
<li class="chapter" data-level="4.6" data-path="working-with-unix.html"><a href="working-with-unix.html#pipes"><i class="fa fa-check"></i><b>4.6</b> Pipes</a><ul>
<li class="chapter" data-level="4.6.1" data-path="working-with-unix.html"><a href="working-with-unix.html#summary-9"><i class="fa fa-check"></i><b>4.6.1</b> Summary</a></li>
<li class="chapter" data-level="4.6.2" data-path="working-with-unix.html"><a href="working-with-unix.html#exercises-7"><i class="fa fa-check"></i><b>4.6.2</b> Exercises</a></li>
</ul></li>
<li class="chapter" data-level="4.7" data-path="working-with-unix.html"><a href="working-with-unix.html#make"><i class="fa fa-check"></i><b>4.7</b> Make</a><ul>
<li class="chapter" data-level="4.7.1" data-path="working-with-unix.html"><a href="working-with-unix.html#summary-10"><i class="fa fa-check"></i><b>4.7.1</b> Summary</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="5" data-path="bash-programming.html"><a href="bash-programming.html"><i class="fa fa-check"></i><b>5</b> Bash Programming</a><ul>
<li class="chapter" data-level="5.1" data-path="bash-programming.html"><a href="bash-programming.html#math"><i class="fa fa-check"></i><b>5.1</b> Math</a><ul>
<li class="chapter" data-level="5.1.1" data-path="bash-programming.html"><a href="bash-programming.html#summary-11"><i class="fa fa-check"></i><b>5.1.1</b> Summary</a></li>
<li class="chapter" data-level="5.1.2" data-path="bash-programming.html"><a href="bash-programming.html#exercises-8"><i class="fa fa-check"></i><b>5.1.2</b> Exercises</a></li>
</ul></li>
<li class="chapter" data-level="5.2" data-path="bash-programming.html"><a href="bash-programming.html#variables"><i class="fa fa-check"></i><b>5.2</b> Variables</a><ul>
<li class="chapter" data-level="5.2.1" data-path="bash-programming.html"><a href="bash-programming.html#summary-12"><i class="fa fa-check"></i><b>5.2.1</b> Summary</a></li>
<li class="chapter" data-level="5.2.2" data-path="bash-programming.html"><a href="bash-programming.html#exercises-9"><i class="fa fa-check"></i><b>5.2.2</b> Exercises</a></li>
</ul></li>
<li class="chapter" data-level="5.3" data-path="bash-programming.html"><a href="bash-programming.html#user-input"><i class="fa fa-check"></i><b>5.3</b> User Input</a><ul>
<li class="chapter" data-level="5.3.1" data-path="bash-programming.html"><a href="bash-programming.html#summary-13"><i class="fa fa-check"></i><b>5.3.1</b> Summary</a></li>
<li class="chapter" data-level="5.3.2" data-path="bash-programming.html"><a href="bash-programming.html#exercises-10"><i class="fa fa-check"></i><b>5.3.2</b> Exercises</a></li>
</ul></li>
<li class="chapter" data-level="5.4" data-path="bash-programming.html"><a href="bash-programming.html#logic-and-ifelse"><i class="fa fa-check"></i><b>5.4</b> Logic and If/Else</a><ul>
<li class="chapter" data-level="5.4.1" data-path="bash-programming.html"><a href="bash-programming.html#conditional-execution"><i class="fa fa-check"></i><b>5.4.1</b> Conditional Execution</a></li>
<li class="chapter" data-level="5.4.2" data-path="bash-programming.html"><a href="bash-programming.html#conditional-expressions"><i class="fa fa-check"></i><b>5.4.2</b> Conditional Expressions</a></li>
<li class="chapter" data-level="5.4.3" data-path="bash-programming.html"><a href="bash-programming.html#if-and-else"><i class="fa fa-check"></i><b>5.4.3</b> If and Else</a></li>
<li class="chapter" data-level="5.4.4" data-path="bash-programming.html"><a href="bash-programming.html#summary-14"><i class="fa fa-check"></i><b>5.4.4</b> Summary</a></li>
<li class="chapter" data-level="5.4.5" data-path="bash-programming.html"><a href="bash-programming.html#exercises-11"><i class="fa fa-check"></i><b>5.4.5</b> Exercises</a></li>
</ul></li>
<li class="chapter" data-level="5.5" data-path="bash-programming.html"><a href="bash-programming.html#arrays"><i class="fa fa-check"></i><b>5.5</b> Arrays</a><ul>
<li class="chapter" data-level="5.5.1" data-path="bash-programming.html"><a href="bash-programming.html#summary-15"><i class="fa fa-check"></i><b>5.5.1</b> Summary</a></li>
<li class="chapter" data-level="5.5.2" data-path="bash-programming.html"><a href="bash-programming.html#exercises-12"><i class="fa fa-check"></i><b>5.5.2</b> Exercises</a></li>
</ul></li>
<li class="chapter" data-level="5.6" data-path="bash-programming.html"><a href="bash-programming.html#braces"><i class="fa fa-check"></i><b>5.6</b> Braces</a><ul>
<li class="chapter" data-level="5.6.1" data-path="bash-programming.html"><a href="bash-programming.html#summary-16"><i class="fa fa-check"></i><b>5.6.1</b> Summary</a></li>
<li class="chapter" data-level="5.6.2" data-path="bash-programming.html"><a href="bash-programming.html#exercises-13"><i class="fa fa-check"></i><b>5.6.2</b> Exercises</a></li>
</ul></li>
<li class="chapter" data-level="5.7" data-path="bash-programming.html"><a href="bash-programming.html#loops"><i class="fa fa-check"></i><b>5.7</b> Loops</a><ul>
<li class="chapter" data-level="5.7.1" data-path="bash-programming.html"><a href="bash-programming.html#for"><i class="fa fa-check"></i><b>5.7.1</b> <code>for</code></a></li>
<li class="chapter" data-level="5.7.2" data-path="bash-programming.html"><a href="bash-programming.html#while"><i class="fa fa-check"></i><b>5.7.2</b> <code>while</code></a></li>
<li class="chapter" data-level="5.7.3" data-path="bash-programming.html"><a href="bash-programming.html#nesting"><i class="fa fa-check"></i><b>5.7.3</b> Nesting</a></li>
<li class="chapter" data-level="5.7.4" data-path="bash-programming.html"><a href="bash-programming.html#summary-17"><i class="fa fa-check"></i><b>5.7.4</b> Summary</a></li>
<li class="chapter" data-level="5.7.5" data-path="bash-programming.html"><a href="bash-programming.html#exercises-14"><i class="fa fa-check"></i><b>5.7.5</b> Exercises</a></li>
</ul></li>
<li class="chapter" data-level="5.8" data-path="bash-programming.html"><a href="bash-programming.html#functions"><i class="fa fa-check"></i><b>5.8</b> Functions</a><ul>
<li class="chapter" data-level="5.8.1" data-path="bash-programming.html"><a href="bash-programming.html#writing-functions"><i class="fa fa-check"></i><b>5.8.1</b> Writing Functions</a></li>
<li class="chapter" data-level="5.8.2" data-path="bash-programming.html"><a href="bash-programming.html#getting-values-from-functions"><i class="fa fa-check"></i><b>5.8.2</b> Getting Values from Functions</a></li>
<li class="chapter" data-level="5.8.3" data-path="bash-programming.html"><a href="bash-programming.html#summary-18"><i class="fa fa-check"></i><b>5.8.3</b> Summary</a></li>
<li class="chapter" data-level="5.8.4" data-path="bash-programming.html"><a href="bash-programming.html#exercises-15"><i class="fa fa-check"></i><b>5.8.4</b> Exercises</a></li>
</ul></li>
<li class="chapter" data-level="5.9" data-path="bash-programming.html"><a href="bash-programming.html#writing-programs"><i class="fa fa-check"></i><b>5.9</b> Writing Programs</a><ul>
<li class="chapter" data-level="5.9.1" data-path="bash-programming.html"><a href="bash-programming.html#the-unix-philosophy"><i class="fa fa-check"></i><b>5.9.1</b> The Unix Philosophy</a></li>
<li class="chapter" data-level="5.9.2" data-path="bash-programming.html"><a href="bash-programming.html#making-programs-executable"><i class="fa fa-check"></i><b>5.9.2</b> Making Programs Executable</a></li>
<li class="chapter" data-level="5.9.3" data-path="bash-programming.html"><a href="bash-programming.html#environmental-variables"><i class="fa fa-check"></i><b>5.9.3</b> Environmental Variables</a></li>
<li class="chapter" data-level="5.9.4" data-path="bash-programming.html"><a href="bash-programming.html#summary-19"><i class="fa fa-check"></i><b>5.9.4</b> Summary</a></li>
<li class="chapter" data-level="5.9.5" data-path="bash-programming.html"><a href="bash-programming.html#exercises-16"><i class="fa fa-check"></i><b>5.9.5</b> Exercises</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="6" data-path="git-and-github.html"><a href="git-and-github.html"><i class="fa fa-check"></i><b>6</b> Git and GitHub</a><ul>
<li class="chapter" data-level="6.1" data-path="git-and-github.html"><a href="git-and-github.html#what-are-git-and-github"><i class="fa fa-check"></i><b>6.1</b> What are Git and GitHub?</a></li>
<li class="chapter" data-level="6.2" data-path="git-and-github.html"><a href="git-and-github.html#setting-up-git-and-github"><i class="fa fa-check"></i><b>6.2</b> Setting Up Git and GitHub</a></li>
<li class="chapter" data-level="6.3" data-path="git-and-github.html"><a href="git-and-github.html#getting-started-with-git"><i class="fa fa-check"></i><b>6.3</b> Getting Started with Git</a><ul>
<li class="chapter" data-level="6.3.1" data-path="git-and-github.html"><a href="git-and-github.html#summary-20"><i class="fa fa-check"></i><b>6.3.1</b> Summary</a></li>
<li class="chapter" data-level="6.3.2" data-path="git-and-github.html"><a href="git-and-github.html#exercises-17"><i class="fa fa-check"></i><b>6.3.2</b> Exercises</a></li>
</ul></li>
<li class="chapter" data-level="6.4" data-path="git-and-github.html"><a href="git-and-github.html#important-git-features"><i class="fa fa-check"></i><b>6.4</b> Important Git Features</a><ul>
<li class="chapter" data-level="6.4.1" data-path="git-and-github.html"><a href="git-and-github.html#getting-help-logs-and-diffs"><i class="fa fa-check"></i><b>6.4.1</b> Getting Help, Logs, and Diffs</a></li>
<li class="chapter" data-level="6.4.2" data-path="git-and-github.html"><a href="git-and-github.html#ignoring-files"><i class="fa fa-check"></i><b>6.4.2</b> Ignoring Files</a></li>
<li class="chapter" data-level="6.4.3" data-path="git-and-github.html"><a href="git-and-github.html#summary-21"><i class="fa fa-check"></i><b>6.4.3</b> Summary</a></li>
<li class="chapter" data-level="6.4.4" data-path="git-and-github.html"><a href="git-and-github.html#exercises-18"><i class="fa fa-check"></i><b>6.4.4</b> Exercises</a></li>
</ul></li>
<li class="chapter" data-level="6.5" data-path="git-and-github.html"><a href="git-and-github.html#branching"><i class="fa fa-check"></i><b>6.5</b> Branching</a><ul>
<li class="chapter" data-level="6.5.1" data-path="git-and-github.html"><a href="git-and-github.html#summary-22"><i class="fa fa-check"></i><b>6.5.1</b> Summary</a></li>
<li class="chapter" data-level="6.5.2" data-path="git-and-github.html"><a href="git-and-github.html#exercises-19"><i class="fa fa-check"></i><b>6.5.2</b> Exercises</a></li>
</ul></li>
<li class="chapter" data-level="6.6" data-path="git-and-github.html"><a href="git-and-github.html#github"><i class="fa fa-check"></i><b>6.6</b> GitHub</a><ul>
<li class="chapter" data-level="6.6.1" data-path="git-and-github.html"><a href="git-and-github.html#markdown"><i class="fa fa-check"></i><b>6.6.1</b> Markdown</a></li>
<li class="chapter" data-level="6.6.2" data-path="git-and-github.html"><a href="git-and-github.html#pull-requests"><i class="fa fa-check"></i><b>6.6.2</b> Pull Requests</a></li>
<li class="chapter" data-level="6.6.3" data-path="git-and-github.html"><a href="git-and-github.html#pages"><i class="fa fa-check"></i><b>6.6.3</b> Pages</a></li>
<li class="chapter" data-level="6.6.4" data-path="git-and-github.html"><a href="git-and-github.html#forking"><i class="fa fa-check"></i><b>6.6.4</b> Forking</a></li>
<li class="chapter" data-level="6.6.5" data-path="git-and-github.html"><a href="git-and-github.html#summary-23"><i class="fa fa-check"></i><b>6.6.5</b> Summary</a></li>
<li class="chapter" data-level="6.6.6" data-path="git-and-github.html"><a href="git-and-github.html#exercises-20"><i class="fa fa-check"></i><b>6.6.6</b> Exercises</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="7" data-path="nephology.html"><a href="nephology.html"><i class="fa fa-check"></i><b>7</b> Nephology</a><ul>
<li class="chapter" data-level="7.1" data-path="nephology.html"><a href="nephology.html#introduction-to-cloud-computing"><i class="fa fa-check"></i><b>7.1</b> Introduction to Cloud Computing</a></li>
<li class="chapter" data-level="7.2" data-path="nephology.html"><a href="nephology.html#setting-up-digitalocean"><i class="fa fa-check"></i><b>7.2</b> Setting Up DigitalOcean</a></li>
<li class="chapter" data-level="7.3" data-path="nephology.html"><a href="nephology.html#connecting-to-the-cloud"><i class="fa fa-check"></i><b>7.3</b> Connecting to the Cloud</a><ul>
<li class="chapter" data-level="7.3.1" data-path="nephology.html"><a href="nephology.html#summary-24"><i class="fa fa-check"></i><b>7.3.1</b> Summary</a></li>
</ul></li>
<li class="chapter" data-level="7.4" data-path="nephology.html"><a href="nephology.html#cloud-computing-basics"><i class="fa fa-check"></i><b>7.4</b> Cloud Computing Basics</a><ul>
<li class="chapter" data-level="7.4.1" data-path="nephology.html"><a href="nephology.html#moving-files-in-and-out-of-the-cloud"><i class="fa fa-check"></i><b>7.4.1</b> Moving Files In and Out of the Cloud</a></li>
<li class="chapter" data-level="7.4.2" data-path="nephology.html"><a href="nephology.html#talking-to-other-servers"><i class="fa fa-check"></i><b>7.4.2</b> Talking to Other Servers</a></li>
<li class="chapter" data-level="7.4.3" data-path="nephology.html"><a href="nephology.html#automating-tasks"><i class="fa fa-check"></i><b>7.4.3</b> Automating Tasks</a></li>
<li class="chapter" data-level="7.4.4" data-path="nephology.html"><a href="nephology.html#summary-25"><i class="fa fa-check"></i><b>7.4.4</b> Summary</a></li>
<li class="chapter" data-level="7.4.5" data-path="nephology.html"><a href="nephology.html#exercises-21"><i class="fa fa-check"></i><b>7.4.5</b> Exercises</a></li>
</ul></li>
<li class="chapter" data-level="7.5" data-path="nephology.html"><a href="nephology.html#shutting-down-a-server"><i class="fa fa-check"></i><b>7.5</b> Shutting Down a Server</a></li>
</ul></li>
<li class="chapter" data-level="8" data-path="start-building.html"><a href="start-building.html"><i class="fa fa-check"></i><b>8</b> Start Building</a><ul>
<li class="chapter" data-level="8.1" data-path="start-building.html"><a href="start-building.html#next-steps"><i class="fa fa-check"></i><b>8.1</b> Next Steps</a></li>
<li class="chapter" data-level="8.2" data-path="start-building.html"><a href="start-building.html#giving-feedback"><i class="fa fa-check"></i><b>8.2</b> Giving Feedback</a></li>
<li class="chapter" data-level="8.3" data-path="start-building.html"><a href="start-building.html#using-this-book"><i class="fa fa-check"></i><b>8.3</b> Using this Book</a></li>
</ul></li>
<li class="divider"></li>
<li><a href="https://github.com/rstudio/bookdown" target="blank">Published with bookdown</a></li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i><a href="./">The Unix Workbench</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<section class="normal" id="section-">
<div id="git-and-github" class="section level1">
<h1><span class="header-section-number">Chapter 6</span> Git and GitHub</h1>
<blockquote>
<p>Proof rather than argument. - Japanese proverb</p>
</blockquote>
<div id="what-are-git-and-github" class="section level2">
<h2><span class="header-section-number">6.1</span> What are Git and GitHub?</h2>
<p>Git is a command line program which allows you to track versions of any code or plain text documents that you create. Like the “track changes” feature of a word processor Git keeps track of who made particular changes, the time and date of those changes, and where the changes were made. If a critical file gets deleted by accident, or if you make a breaking change to your code and you want to try to figure out where the breaking change was made, you can use Git to restore the deleted file or find the new bug in your program. Git organizes groups of files that you’re tracking into a <strong>repository</strong>, which is just a directory where all of the changes to files in that directory are tracked. Git can also help you collaborate with others when you’re writing software. As <a href="https://twitter.com/kwbroman">Karl Broman</a> says (paraphrasing <a href="https://twitter.com/mtholder">Mark Holder</a>): “Your closest collaborator is you six months ago, but you don’t reply to emails.”</p>
<p>GitHub is a website that provides remote Git repositories. A remote repository is just a Git repository that you’re able to access over an internet connection. GitHub allows you to create public remote repositories for free, and anyone can see your code in these public repositories. If you want to keep your code private then you can pay GitHub for private remote repositories.</p>
<p>If you’re working on code together with a friend GitHub can help you sync changes to code files between you and your friend. There’s also a social and community aspect to GitHub, since you can watch other programmers develop their projects. GitHub also makes it easy to jump in and help somebody with their project. GitHub offers many other useful features which we will discuss at length.</p>
</div>
<div id="setting-up-git-and-github" class="section level2">
<h2><span class="header-section-number">6.2</span> Setting Up Git and GitHub</h2>
<p>Before setting up Git, go to <a href="https://github.com/">GitHub</a> and create a free account. Take note of which email address you use and which username you choose.</p>
<p>To see if you have Git installed open up your terminal and enter the following:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> --version</code></pre></div>
<pre><code>## git version 2.14.3 (Apple Git-98)</code></pre>
<p>If you don’t get a response back telling you the version of Git that you have installed then you need to install Git. You can find instructions for installing Git on your operating system <a href="https://git-scm.com/book/en/v2/Getting-Started-Installing-Git">here</a>.</p>
<p>Open up your shell once you have git installed and run <code>git --version</code> again to make sure that installation succeeded (you may need to restart your shell or your computer). After Git is installed we need to set up two environmental variables, but we only need to do this once. The first variable we need to set up with Git is your GitHub user name, and the second variable is the email address that you used to create your GitHub account:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> config --global user.name <span class="st">"myUserName"</span>
<span class="fu">git</span> config --global user.email [email protected]</code></pre></div>
</div>
<div id="getting-started-with-git" class="section level2">
<h2><span class="header-section-number">6.3</span> Getting Started with Git</h2>
<p>Let’s create our first Git repository. First we need to create a directory:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="bu">cd</span>
<span class="fu">mkdir</span> my-first-repo
<span class="bu">cd</span> my-first-repo</code></pre></div>
<p>“Repo” in this case is just shorthand for “repository.” To start tracking files with Git in a directory enter <code>git init</code> into the command line:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> init</code></pre></div>
<pre><code>## Initialized empty Git repository in /Users/sean/my-first-repo/.git/</code></pre>
<p>You’ve just created your first repository! Now let’s create a file and start tracking it.</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="bu">echo</span> <span class="st">"Welcome to My First Repo"</span> <span class="op">></span> readme.txt</code></pre></div>
<p>Now that we’ve created a file in this Git repository, let’s use <code>git status</code> to see what’s going on in this repository. We’ll be using <code>git status</code> continuously throughout this chapter in order to get information about the status of this Git repository.</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> status</code></pre></div>
<pre><code>## On branch master
##
## Initial commit
##
## Untracked files:
## (use "git add <file>..." to include in what will be committed)
##
## readme.txt
##
## nothing added to commit but untracked files present (use "git add" to track)</code></pre>
<p>As you can see <code>readme.txt</code> is listed as an untracked file. In order to let Git know that you want to track this file we need to use <code>git add</code> with the name of the file that we want to track. Let’s start tracking <code>readme.txt</code>:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> add readme.txt</code></pre></div>
<p>Git now knows to track any changes to <code>readme.txt</code>. Let’s see how the status of the repository has changed:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> status</code></pre></div>
<pre><code>## On branch master
##
## Initial commit
##
## Changes to be committed:
## (use "git rm --cached <file>..." to unstage)
##
## new file: readme.txt
##</code></pre>
<p>Git is now tracking <code>readme.txt</code>, or in Git-specific language <code>readme.txt</code> is now <strong>staged</strong>. Between the parentheses in the message above you can see that <code>git status</code> is giving us a tip about how to unstage (or un-track) this file, which we could do with <code>git rm --cached readme.txt</code>. Let’s unstage this file just to see what happens:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> rm --cached readme.txt</code></pre></div>
<pre><code>## rm 'readme.txt'</code></pre>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> status</code></pre></div>
<pre><code>## On branch master
##
## Initial commit
##
## Untracked files:
## (use "git add <file>..." to include in what will be committed)
##
## readme.txt
##</code></pre>
<p>Our repository is right back to the way it started with <code>readme.txt</code> as an unstaged file. Let’s start tracking <code>readme.txt</code> again so we can move on to cooler Git features.</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> add readme.txt</code></pre></div>
<p>Now that Git is tracking <code>readme.txt</code> we need to create a milestone to indicate the changes that we made to <code>readme.txt</code>. In this case, the changes that we made were creating the file in the first place! This milestone is called a <strong>commit</strong> in Git. A commit logs the content of all of the currently staged files. Right now we only have <code>readme.txt</code> staged so let’s commit the creation of this file. When making a Git commit, we need to write a commit message which is specified after the <code>-m</code> flag. The message should briefly describe what changes you’ve made since the last commit.</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> commit -m <span class="st">"added readme.txt"</span></code></pre></div>
<pre><code>## [master (root-commit) 73e53ca] added readme.txt
## 1 file changed, 1 insertion(+)
## create mode 100644 readme.txt</code></pre>
<p>The message above confirms that the commit succeeded and it summarizes the changes that took place since the last commit. As you can see in the message we only changed one file, and we only changed one line in that file. Let’s run <code>git status</code> again to see the state of our repository after we’ve made the first commit:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> status</code></pre></div>
<pre><code>## On branch master
## nothing to commit, working tree clean</code></pre>
<p>All of the changes to the files in this repository have been committed! Let’s add a few more files to this repository and commit them.</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">touch</span> file1.txt
<span class="fu">touch</span> fil2.txt
<span class="fu">ls</span></code></pre></div>
<pre><code>## file1.txt
## fil2.txt
## readme.txt</code></pre>
<p>While we’re at it let’s also add a new line of text to <code>readme.txt</code>:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="bu">echo</span> <span class="st">"Learning Git is going well so far."</span> <span class="op">>></span> readme.txt</code></pre></div>
<p>Now that we’ve added two more files and we’ve made changes to one file let’s take a look at the state of this repository.</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> status</code></pre></div>
<pre><code>## On branch master
## Changes not staged for commit:
## (use "git add <file>..." to update what will be committed)
## (use "git checkout -- <file>..." to discard changes in working directory)
##
## modified: readme.txt
##
## Untracked files:
## (use "git add <file>..." to include in what will be committed)
##
## fil2.txt
## file1.txt
##
## no changes added to commit (use "git add" and/or "git commit -a")</code></pre>
<p>We can see that Git has detected that one file has been modified, and that there are two files in this directory that it is not tracking. Now we need to tell Git to track the changes to these files. We could tell Git to track changes to each file using <code>git add</code>, or since all of the files in this repository are <code>.txt</code> files we could use a wildcard and enter <code>git add *.txt</code> into the console. However if we want to track all of the changes to all of the files in our directory we should use the command <code>git add -A</code>.</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> add -A
<span class="fu">git</span> status</code></pre></div>
<pre><code>## On branch master
## Changes to be committed:
## (use "git reset HEAD <file>..." to unstage)
##
## new file: fil2.txt
## new file: file1.txt
## modified: readme.txt
##</code></pre>
<p>Now the changes to all of the files in this repository are being tracked. Finally let’s commit these changes:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> commit -m <span class="st">"added two files"</span></code></pre></div>
<pre><code>## [master 53a1983] added two files
## 3 files changed, 1 insertion(+)
## create mode 100644 fil2.txt
## create mode 100644 file1.txt</code></pre>
<p>Darn it, now looking at this commit summary I realize that I have a typo in one of the names of my files! Thankfully we can undo the most recent commit with the command <code>git reset --soft HEAD~</code>:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> reset --soft HEAD~
<span class="fu">git</span> status</code></pre></div>
<pre><code>## On branch master
## Changes to be committed:
## (use "git reset HEAD <file>..." to unstage)
##
## new file: fil2.txt
## new file: file1.txt
## modified: readme.txt
##</code></pre>
<p>This repo is now in that exact same state it was right before we made the commit. Now we can rename <code>fil2.txt</code> to <code>file2.txt</code>, then let’s look at the status of the repository again.</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">mv</span> fil2.txt file2.txt
<span class="fu">git</span> status</code></pre></div>
<pre><code>## On branch master
## Changes to be committed:
## (use "git reset HEAD <file>..." to unstage)
##
## new file: fil2.txt
## new file: file1.txt
## modified: readme.txt
##
## Changes not staged for commit:
## (use "git add/rm <file>..." to update what will be committed)
## (use "git checkout -- <file>..." to discard changes in working directory)
##
## deleted: fil2.txt
##
## Untracked files:
## (use "git add <file>..." to include in what will be committed)
##
## file2.txt
##</code></pre>
<p>We previously told Git to track <code>fil2.txt</code>, and we can see that Git acknowledges that the file has been deleted. We can bring Git up to speed with what files it should be tracking with <code>git add -A</code>:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> add -A
<span class="fu">git</span> status</code></pre></div>
<pre><code>## On branch master
## Changes to be committed:
## (use "git reset HEAD <file>..." to unstage)
##
## new file: file1.txt
## new file: file2.txt
## modified: readme.txt
##</code></pre>
<p>Finally we got the file names right! Now let’s make the correct commit:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> commit -m <span class="st">"added two files"</span></code></pre></div>
<pre><code>## [master 12bb9f5] added two files
## 3 files changed, 1 insertion(+)
## create mode 100644 file1.txt
## create mode 100644 file2.txt</code></pre>
<p>That looks much better.</p>
<div id="summary-20" class="section level3">
<h3><span class="header-section-number">6.3.1</span> Summary</h3>
<ul>
<li>Git tracks changes to plain text files (code files and text documents).</li>
<li>A directory where changes to files are tracked by Git is called a Git repository.</li>
<li>Change your working directory, then run <code>git init</code> to start a repository.</li>
<li>You can track changes to a file using <code>git add [names of files]</code>.</li>
<li>You can create a milestone about the state of your files using <code>git commit -m "message about changes since the last commit"</code>.</li>
<li>To examine the state of files in your repository use <code>git status</code>.</li>
</ul>
</div>
<div id="exercises-17" class="section level3">
<h3><span class="header-section-number">6.3.2</span> Exercises</h3>
<ol style="list-style-type: decimal">
<li>Start a repository in a new directory.</li>
<li>Create a new file in your new Git repository. Make sure Git is tracking the file and then create a new commit.</li>
<li>Make changes to the file, and then commit these changes.</li>
<li>Add two new files to your repository, but only commit one of them. What is the status of your repository after the commit?</li>
<li>Undo the last commit, add the untracked file, and redo the commit.</li>
</ol>
</div>
</div>
<div id="important-git-features" class="section level2">
<h2><span class="header-section-number">6.4</span> Important Git Features</h2>
<div id="getting-help-logs-and-diffs" class="section level3">
<h3><span class="header-section-number">6.4.1</span> Getting Help, Logs, and Diffs</h3>
<p>Git commands have their own <code>man</code> pages. You can access them with <code>git help [name of command]</code>. For example here’s the start of the help page for <code>git status</code>:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> help status</code></pre></div>
<pre><code>GIT-STATUS(1) Git Manual GIT-STATUS(1)
NAME
git-status - Show the working tree status
SYNOPSIS
git status [<options>...] [--] [<pathspec>...]
DESCRIPTION
Displays paths that have differences between the index file and the current HEAD commit,
paths that have differences between the working tree and the index file, and paths in the
working tree that are not tracked by Git (and are not ignored by gitignore(5)). The first
are what you would commit by running git commit; the second and third are what you could
commit by running git add before running git commit.</code></pre>
<p>Just like any other help page that uses <code>less</code>, you can return to the prompt with the <code>Q</code> key.</p>
<p>If you want to see a list of your Git commits, enter <code>git log</code> into the console:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> log</code></pre></div>
<pre><code>## commit 12bb9f53b10c9b720dac8441e8624370e4e071b6
## Author: seankross <[email protected]>
## Date: Fri Apr 21 15:23:59 2017 -0400
##
## added two files
##
## commit 73e53cae75301ce9b2802107b1956447241bb17a
## Author: seankross <[email protected]>
## Date: Thu Apr 20 14:15:26 2017 -0400
##
## added readme.txt</code></pre>
<p>If you’ve made many commits to a repository you might need to press the <code>Q</code> key in order to get back to the prompt. Each commit has its time, date, and commit message recorded, along with a SHA-1 hash that uniquely identifies the commit.</p>
<p>Git can also help show the differences between unstaged changes to your files compared to the last commit. Let’s add a new line of text to <code>readme.txt</code>:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="bu">echo</span> <span class="st">"The third line."</span> <span class="op">>></span> readme.txt
<span class="fu">git</span> diff readme.txt</code></pre></div>
<pre><code>## diff --git a/readme.txt b/readme.txt
## index b965f6a..a3db358 100644
## --- a/readme.txt
## +++ b/readme.txt
## @@ -1,2 +1,3 @@
## Welcome to My First Repo
## Learning Git is going well so far.
## +I added a line.</code></pre>
<p>As you can see a plus sign shows up next to the added line. Now let’s open up this file in a text editor so we can delete the second line.</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">nano</span> readme.txt
<span class="co"># Delete the second line</span>
<span class="fu">git</span> diff readme.txt</code></pre></div>
<pre><code>## diff --git a/readme.txt b/readme.txt
## index b965f6a..e173fdf 100644
## --- a/readme.txt
## +++ b/readme.txt
## @@ -1,2 +1,2 @@
## Welcome to My First Repo
## -Learning Git is going well so far.
## +I added a line.</code></pre>
<p>A minus sign appears next to the line we deleted. Let’s take a look at the status of our directory at this point.</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> status</code></pre></div>
<pre><code>## On branch master
## Changes not staged for commit:
## (use "git add <file>..." to update what will be committed)
## (use "git checkout -- <file>..." to discard changes in working directory)
##
## modified: readme.txt
##
## no changes added to commit (use "git add" and/or "git commit -a")</code></pre>
<p>If you read the results from <code>git status</code> carefully you can see that we can take this repository in one of two directions at this point. We can either <code>git add</code> the files we’ve made changes to in order to track those changes, or we can use <code>git checkout</code> in order to remove all of the changes we’ve made to a file to restore its content to what was present in the last commit. Let’s remove our changes to see how this works.</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">cat</span> readme.txt</code></pre></div>
<pre><code>## Welcome to My First Repo
## I added a line.</code></pre>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> checkout readme.txt
<span class="fu">cat</span> readme.txt</code></pre></div>
<pre><code>## Welcome to My First Repo
## Learning Git is going well so far.</code></pre>
<p>And as you can see the changes we made to <code>readme.txt</code> have been undone.</p>
</div>
<div id="ignoring-files" class="section level3">
<h3><span class="header-section-number">6.4.2</span> Ignoring Files</h3>
<p>Sometimes you might have files that you never want Git to track, for example binary files that are generated as by-products of running code (PDFs or images), or secrets like passwords or API keys. A file in your Git repository called <code>.gitignore</code> can list names of files and sub-folders, or simple regular expressions (whatever you can use with <code>ls</code>) in order to specify files which should never be tracked. Each line of a <code>.gitignore</code> file should specify a file or group of files that should not be tracked by Git. Let’s make a <code>.gitignore</code> file to make sure that we never track image files in this repository:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">touch</span> toby.jpg
<span class="fu">git</span> status</code></pre></div>
<pre><code>## On branch master
## Untracked files:
## (use "git add <file>..." to include in what will be committed)
##
## toby.jpg
##
## nothing added to commit but untracked files present (use "git add" to track)</code></pre>
<p>Now that we’ve added an image to our repository, let’s add a <code>.gitignore</code> file to make sure Git doesn’t track these kinds of files.</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="bu">echo</span> <span class="st">"*.jpg"</span> <span class="op">></span> .gitignore
<span class="fu">git</span> status</code></pre></div>
<pre><code>## On branch master
## Untracked files:
## (use "git add <file>..." to include in what will be committed)
##
## .gitignore
##
## nothing added to commit but untracked files present (use "git add" to track)</code></pre>
<p>Now we can see that Git has detected the new <code>.gitignore</code> file, but it doesn’t see <code>toby.jpg</code>. Let’s add and commit our <code>.gitignore</code> file:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> add -A
<span class="fu">git</span> commit -m <span class="st">"added gitignore"</span></code></pre></div>
<pre><code>## [master adef548] added gitignore
## 1 file changed, 1 insertion(+)
## create mode 100644 .gitignore</code></pre>
<p>Now if we add another <code>.jpg</code> file, Git will not see the file:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">touch</span> bernie.jpg
<span class="fu">git</span> status</code></pre></div>
<pre><code>## On branch master
## nothing to commit, working tree clean</code></pre>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">ls</span></code></pre></div>
<pre><code>## bernie.jpg
## toby.jpg
## file1.txt
## file2.txt
## readme.txt</code></pre>
</div>
<div id="summary-21" class="section level3">
<h3><span class="header-section-number">6.4.3</span> Summary</h3>
<ul>
<li><code>git help</code> allows you to read the <code>man</code> pages for specific Git commands.</li>
<li><code>git log</code> will show you your commit history.</li>
<li><code>git diff</code> displays what has changed between the last commit and your current untracked changes.</li>
<li>You can specify a <code>.gitignore</code> file in order to tell Git not to track certain files.</li>
</ul>
</div>
<div id="exercises-18" class="section level3">
<h3><span class="header-section-number">6.4.4</span> Exercises</h3>
<ol style="list-style-type: decimal">
<li>Look at the help pages for <code>git log</code> and <code>git diff</code>.</li>
<li>Add to the <code>.gitignore</code> you already started to include a specific file name, then add that file to your repository.</li>
<li>Create a file that contains the Git log for this repository. Use <code>grep</code> to see which day of the week most of the commits occurred on.</li>
</ol>
</div>
</div>
<div id="branching" class="section level2">
<h2><span class="header-section-number">6.5</span> Branching</h2>
<p>Branching is one of the most powerful features that Git offers. Creating different Git branches allows you to work on a particular feature or set of files independently from other “copies” of a repository. That way you and a friend can work on different parts of the same file on different branches, and then Git can help you elegantly merge your branches and changes together.</p>
<p>You can list all of the available branches with the command <code>git branch</code>:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> branch</code></pre></div>
<pre><code>## * master</code></pre>
<p>The star (<code>*</code>) indicates which branch you’re currently on. The default branch that is created is always called <em>master</em>. Usually people use this branch as the working version of the software that they are writing, while they develop new and potentially unstable features on other branches.</p>
<p>To add a branch we’ll also use the <code>git branch</code> command, followed the name of the branch we want to create:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> branch my-new-feature</code></pre></div>
<p>Now let’s enter <code>git branch</code> again to confirm that we’ve created the branch:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> branch</code></pre></div>
<pre><code>## * master
## my-new-feature</code></pre>
<p>We can make <code>my-new-feature</code> the current branch using <code>git checkout</code> with the name of the branch:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> checkout my-new-feature</code></pre></div>
<pre><code>## Switched to branch 'my-new-feature'</code></pre>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> branch</code></pre></div>
<pre><code>## master
## * my-new-feature</code></pre>
<p>If we look at <code>git status</code> we can also see that it will tell us which branch we’re on:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> status</code></pre></div>
<pre><code>On branch my-new-feature
nothing to commit, working tree clean</code></pre>
<p>We can switch back to the <code>master</code> branch using <code>git checkout</code>:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> checkout master</code></pre></div>
<pre><code>## Switched to branch 'master'</code></pre>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> branch</code></pre></div>
<pre><code>## * master
## my-new-feature</code></pre>
<p>Now we can delete a branch by using the <code>-d</code> flag with <code>git branch</code> and the name of the branch we want to delete:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> branch -d my-new-feature</code></pre></div>
<pre><code>## Deleted branch my-new-feature (was adef548).</code></pre>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> branch</code></pre></div>
<pre><code>## * master</code></pre>
<p>Let’s create a new branch for adding a section to the <code>readme.txt</code> in our repository. We can create a new branch and switch to that branch at the same time using the command <code>git checkout -b</code> and the name of the new branch we want to create:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> checkout -b update-readme</code></pre></div>
<pre><code>## Switched to a new branch 'update-readme'</code></pre>
<p>Now that we’ve created and switched to a new branch, let’s make some changes to a file. As you might be expecting right now we’ll add a new line to <code>readme.txt</code>:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="bu">echo</span> <span class="st">"I added this line in the update-readme branch."</span> <span class="op">>></span> readme.txt
<span class="fu">cat</span> readme.txt</code></pre></div>
<pre><code>## Welcome to My First Repo
## Learning Git is going well so far.
## I added this line in the update-readme branch.</code></pre>
<p>Now that we’ve added a new line let’s commit these changes:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> add -A
<span class="fu">git</span> commit -m <span class="st">"added a third line to readme.txt"</span></code></pre></div>
<pre><code>## [update-readme 6e378a9] added a third line to readme.txt
## 1 file changed, 1 insertion(+)</code></pre>
<p>Now that we’ve made a commit on the <code>update-readme</code> branch, let’s switch back to the <code>master</code> branch, and then we’ll take a look at <code>readme.txt</code>:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> checkout master</code></pre></div>
<pre><code>## Switched to branch 'master'</code></pre>
<p>Now that we’re on the <code>master</code> branch let’s quickly glance at <code>readme.txt</code>:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">cat</span> readme.txt</code></pre></div>
<pre><code>## Welcome to My First Repo
## Learning Git is going well so far.</code></pre>
<p>The third line that we added is gone! Don’t fret, the line that we added isn’t gone forever. We committed the change to this file while we were on the <code>update-readme</code> branch, so the updated file is safely in that branch. Let’s switch back to that branch just to make sure:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> checkout update-readme
<span class="fu">cat</span> readme.txt</code></pre></div>
<pre><code>## Welcome to My First Repo
## Learning Git is going well so far.
## I added this line in the update-readme branch.</code></pre>
<p>And the third line is back! Let’s add and commit yet another line while we’re on this branch:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="bu">echo</span> <span class="st">"It's sunny outside today."</span> <span class="op">>></span> readme.txt
<span class="fu">git</span> add -A
<span class="fu">git</span> commit -m <span class="st">"added weather info"</span></code></pre></div>
<pre><code>## [update-readme d7946e9] added weather info
## 1 file changed, 1 insertion(+)</code></pre>
<p>This is a small example of how to use Git branching, but you can see how you can make incremental edits to plain text (usually code files) without effecting the <code>master</code> branch (the tested and working copy of your software) and without effecting any other branches. You can imagine how this system could be used for multiple people to work on the same codebase at the same time, or how you could develop and test multiple software features without them interfering with each other. Now that we’ve made a couple of changes to <code>readme.txt</code>, let’s combine those changes with what we have in the <code>master</code> branch. This is made possible by a Git <strong>merge</strong>. Merging allows you to elegantly combine the changes that have been made between two branches. Let’s merge the changes we made in the <code>update-readme</code> branch with the <code>master</code> branch. Git incorporates other branches into the current branch by default. When you’re merging, the current branch is also called the <strong>base</strong> branch. Let’s switch to the <code>master</code> branch so we can merge in the changes from the <code>update-readme</code> branch:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> checkout master</code></pre></div>
<pre><code>## Switched to branch 'master'</code></pre>
<p>To merge in the changes from another branch we need to use <code>git merge</code> and the name of the branch:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> merge update-readme</code></pre></div>
<pre><code>## Updating adef548..d7946e9
## Fast-forward
## readme.txt | 2 ++
## 1 file changed, 2 insertions(+)</code></pre>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">cat</span> readme.txt</code></pre></div>
<pre><code>## Welcome to My First Repo
## Learning Git is going well so far.
## I added this line in the update-readme branch.
## It's sunny outside today.</code></pre>
<p>It looks like you’ve merged your first branch in Git! Branching is part of what makes Git so powerful since it enables parallel developments on the same code base. But what if there are two commits in two separate branches that make different edits to the same line of text? When this occurs it is called a <strong>conflict</strong>. Let’s create a conflict so we can learn how they can be resolved.</p>
<p>First we’ll switch to the <code>update-readme</code> branch. Use <code>nano</code> to edit the last line of <code>readme.txt</code>, then commit your changes:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> checkout update-readme
<span class="fu">nano</span> readme.txt
<span class="fu">cat</span> readme.txt</code></pre></div>
<pre><code>## Welcome to My First Repo
## Learning Git is going well so far.
## I added this line in the update-readme branch.
## It's cloudy outside today.</code></pre>
<p>Notice that we changed “sunny” to “cloudy” in the last line.</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> add -A
<span class="fu">git</span> commit -m <span class="st">"changed sunny to cloudy"</span></code></pre></div>
<p>Now that our changes are committed on the <code>update-readme</code> branch, let’s switch back to <code>master</code>:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> checkout master</code></pre></div>
<p>Let’s change the same line of code using <code>nano</code>:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">nano</span> readme.txt
<span class="fu">cat</span> readme.txt</code></pre></div>
<pre><code>## Welcome to My First Repo
## Learning Git is going well so far.
## I added this line in the update-readme branch.
## It's windy outside today.</code></pre>
<p>Now let’s commit these changes:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> add -A
<span class="fu">git</span> commit -m <span class="st">"changed sunny to windy"</span></code></pre></div>
<p>We’ve now created two commits that directly conflict with each other. On the <code>update-readme</code> branch the last line says <code>It's cloudy outside today.</code>, while on the <code>master</code> branch the last line says <code>It's windy outside today.</code>. Let’s see what happens when we try to merge <code>update-readme</code> into <code>master</code>.</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> merge update-readme</code></pre></div>
<pre><code>## Auto-merging readme.txt
## CONFLICT (content): Merge conflict in readme.txt
## Automatic merge failed; fix conflicts and then commit the result.</code></pre>
<p>Uh-oh, there’s a conflict! Let’s check the status of the repo right now:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> status</code></pre></div>
<pre><code>## On branch master
## You have unmerged paths.
## (fix conflicts and run "git commit")
## (use "git merge --abort" to abort the merge)
##
## Unmerged paths:
## (use "git add <file>..." to mark resolution)
##
## both modified: readme.txt
##
## no changes added to commit (use "git add" and/or "git commit -a")</code></pre>
<p>If you’re getting used to reading the result of <code>git status</code>, you can see that it often offers suggestions about what steps you should take next. Git is indicating that both versions of readme.txt have modified the same text. Let’s take a look at <code>readme.txt</code> to see what’s going on there:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">cat</span> readme.txt</code></pre></div>
<pre><code>## Welcome to My First Repo
## Learning Git is going well so far.
## I added this line in the update-readme branch.
## <<<<<<< HEAD
## It's windy outside today.
## =======
## It's cloudy outside today.
## >>>>>>> update-readme</code></pre>
<p>The first three lines of this file look normal, then things get interesting! The line between <code><<<<<<< HEAD</code> and <code>=======</code> shows the version of the conflicted line on the current branch. In Git terminology the <code>HEAD</code> represents the most recent commit on the branch which is currently checked out (which is <code>master</code> in this case). The line between <code>=======</code> and <code>>>>>>>> update-readme</code> shows the version of the line on the <code>update-readme</code> branch. In order to resolve this conflict, all we need to do is open <code>readme.txt</code> with <code>nano</code> so we can delete the lines we want to get rid of. In this case let’s keep the “cloudy” version.</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">nano</span> readme.txt
<span class="fu">cat</span> readme.txt</code></pre></div>
<pre><code>## Welcome to My First Repo
## Learning Git is going well so far.
## I added this line in the update-readme branch.
## It's cloudy outside today.</code></pre>
<p>Now we can commit the resolution of this conflict.</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> add -A
<span class="fu">git</span> commit -m <span class="st">"resolved conflict"</span></code></pre></div>
<p>You’re now familiar with this basics of Git! If you want to go into further depth with your study of Git I highly recommend the free and open source book <a href="https://git-scm.com/book/">Pro Git</a>.</p>
<div id="summary-22" class="section level3">
<h3><span class="header-section-number">6.5.1</span> Summary</h3>
<ul>
<li>Git branching allows you and others to work on the same code base together.</li>
<li>You can create a branch with the command <code>git branch [name of branch]</code>.</li>
<li>To switch to a branch use <code>git checkout [name of branch]</code>.</li>
<li>You can combine a branch with your current branch by using <code>git merge</code>.</li>
</ul>
</div>
<div id="exercises-19" class="section level3">
<h3><span class="header-section-number">6.5.2</span> Exercises</h3>
<ol style="list-style-type: decimal">
<li>Start a new branch.</li>
<li>Switch to that branch and add commits to it. Switch to an older branch and then merge the new branch into your current branch.</li>
<li>Purposefully create and resolve a merge conflict.</li>
</ol>
</div>
</div>
<div id="github" class="section level2">
<h2><span class="header-section-number">6.6</span> GitHub</h2>
<p>Now that you know the basics of using Git, let’s talk about how you can share your work and start collaborating online using GitHub. As an added bonus, by the end of this chapter you will have created your very own website! To get started go to <a href="https://github.com/">GitHub</a> and sign in with the credentials we set up at the beginning of the chapter. After you sign in you should see a plus-sign near the top-right corner of your web browser. Click the plus-sign and a little menu should appear, then click “New repository.” You should now see a screen that looks like this:</p>
<div class="figure">
<img src="images/new-repo.png" />
</div>
<p>In the text box under <strong>Repository name</strong> type <code>my-first-repo</code> and then click the green <strong>Create repository</strong> button. Now you should see a page like this:</p>
<p><img src="images/quick-setup.png" /> GitHub offers a few suggestions about what to do with our new remote repository. We’ve already been using a local Git repository, and what GitHub provides is a <strong>remote</strong> Git repository. A remote Git repository is just a Git repository stored on a computer is that always turned on and connected to the internet, so it can act as a central point where we can share and sync our changes to files with our friends and colleagues. We can see which remote repositories our local repository is connected to with the <code>git remote</code> command while we have our working directory set to <code>my-first-repo</code>:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> remote</code></pre></div>
<p>Nothing is printed to the console since you haven’t set any remotes up yet! Now let’s add your new GitHub repository as a remote in your local repository:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> remote add origin https://github.com/seankross/my-first-repo.git</code></pre></div>
<p>In the command above <code>git remote add</code> adds a new remote to your local repository, <code>origin</code> is the name we’re assigning to this remote repository, and <code>https://github.com/seankross/my-first-repo.git</code> is the URL of the remote repository. You should of course substitute <code>seankross</code> for your GitHub user name so that it corresponds to your remote repository URL. Later I’ll explain why “origin” is the name we chose for this remote. Let’s run <code>git remote</code> again to confirm that we added the <code>origin</code> remote successfully:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> remote</code></pre></div>
<pre><code>## origin</code></pre>
<p>Now that we’ve added our GitHub remote, let’s perform our first Git <strong>push</strong>. A Git push updates a remote repository with all of the commits that we’ve made to our local Git repository. This first Git push you do when setting up a remote on GitHub with a local repository is a little different from future Git pushes. We’ll need to use the <code>-u</code> flag in order to set <code>origin</code> as the default remote repository so we don’t have to provide its name every time we want to interact with it. Enter the following command, modified so that you’re using your GitHub user name:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> push -u origin master</code></pre></div>
<pre><code>## Counting objects: 23, done.
## Delta compression using up to 4 threads.
## Compressing objects: 100% (19/19), done.
## Writing objects: 100% (23/23), 1.88 KiB | 0 bytes/s, done.
## Total 23 (delta 9), reused 0 (delta 0)
## remote: Resolving deltas: 100% (9/9), done.
## To https://github.com/seankross/my-first-repo.git
## * [new branch] master -> master
## Branch master set up to track remote branch master from origin.</code></pre>
<p>The command above pushed all of our commits to the remote repository on GitHub, and it set up the <code>master</code> branch of the <code>origin</code> remote repository as the default remote repository. Looking back at the web page for your repository on GitHub, it should look something like this:</p>
<div class="figure">
<img src="images/first-push.png" />
</div>
<p>One neat feature of GitHub is that readme files are rendered on the repository page so you can write documents which explain the contents of your repository. Let’s get more creative with these readme documents by learning a small language called Markdown.</p>
<div id="markdown" class="section level3">
<h3><span class="header-section-number">6.6.1</span> Markdown</h3>
<p>Markdown is a markup language. Markup languages are sets of rules for adding decorative features to text. The most popular markup language is HTML, but you might have also heard of XML and LaTeX. Markdown is a powerful markup language because it’s small, intuitive, and readable when it’s written as plain text. GitHub transforms Markdown files (which end in the file extension <code>.md</code>) into simple HTML web pages in your repository. If there is a file called <code>README.md</code> in any folder in your repository, then that file is rendered to HTML and displayed on GitHub. Let’s create a <code>README.md</code> file for our repository. First we’ll destroy the plain text readme file we already have:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">rm</span> readme.txt</code></pre></div>
<p>I’ve included a Markdown file below that attempts to explain some of Markdown’s features. Copy the plain text below, create a new file called <code>README.md</code> with <code>nano</code>, paste the text in, and then save the file.</p>
<pre><code># This is a large heading
## This is a smaller heading
And as **imagination** bodies forth,
The forms of things *unknown*, the poet’s pen,
Turns them to shapes and gives to airy nothing,
A local *habitation* and a **name**.
- This is
- an unordered
- list
1. This is
2. an ordered
3. list
Here is `some code` in the middle of a sentence.
```
This is
a block
of code
```
Here is how you make [a link](https://www.wikipedia.org/).
</code></pre>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">nano</span> README.md</code></pre></div>
<p>Now let’s add our changes, make a commit, and push those changes to our remote repository:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> add -A
<span class="fu">git</span> commit -m <span class="st">"added README.md"</span>
<span class="fu">git</span> push</code></pre></div>
<pre><code>## Counting objects: 3, done.
## Delta compression using up to 4 threads.
## Compressing objects: 100% (3/3), done.
## Writing objects: 100% (3/3), 659 bytes | 0 bytes/s, done.
## Total 3 (delta 0), reused 0 (delta 0)
## To https://github.com/seankross/my-first-repo.git
## ca04f67..2169912 master -> master</code></pre>
<p>Since we set up a default remote repository the first time we pushed, we can now simply enter <code>git push</code> in order to send our latest commits to the <code>master</code> branch on the <code>origin</code> remote. Now the page on GitHub for your repository should look something like this:</p>
<div class="figure">
<img src="images/md-readme.png" />
</div>
<p>We’ve got a much more complex readme file! Notice how the plain text that we wrote has been rendered according to a few rules:</p>
<ul>
<li>Pound signs (<code>#</code>, <code>##</code>) make headings.</li>
<li>A word surrounded by single asterisks (<code>*word*</code>) makes that word <em>italicized</em>.</li>
<li>A word surrounded by double asterisks (<code>**word**</code>) makes that word <strong>bold</strong>.</li>
<li>You can create lists with hyphens (<code>-</code>) or numbers (<code>1., 2., 3.</code>).</li>
<li>Code can be placed in the middle of a line with single backticks (<code>`code`</code>).</li>
<li>A code block can be created by putting code in between a set of triple backticks (<code>```</code>).</li>
<li>You can insert a link with brackets and parentheses (<code>[Link text here](http://jhu.edu)</code>).</li>
<li>You can use an image with an exclamation point, and a link to an image (<code></code>)</li>
</ul>
<p>Personally I really enjoy writing with Markdown, to the point where I wrote <a href="https://github.com/seankross/the-unix-workbench/blob/master/docs/06-Git-and-GitHub.md">this entire book</a> in Markdown! We’re going to be using Markdown for the rest of this chapter, so I suggest that you take a few minutes to play around with the syntax in <a href="https://jbt.github.io/markdown-editor/#TVFLbtwwDN3rFCxm0xgTOU133WXXA2QXFDDHYizWEmlIctzZ9Rq9Xk9SetqZFNCCIt97/LwDPEeuYA8hYZkIImFgmZw7HP6r1YwpUXmvPkkArNB1nHFiwcYqXQcnDUwVXrW0eHTPkfYwV9BXaNGIxlhlFt2kO1qGYFFqv3/+qrCQGGEtUvd8hqZQIy4mhtZq4jeLLIdcziB6ETu6J0g6YoIu4onb3yEueLTJBDN1nXfu/rqIRSiwipZAhYJ9E9fm3Cd/Qzz6HXIFfPb/EF/tu19iqJoJRg00AMtlg8whJNo3tDORNJKRrOkwDO4qinCyOWdnmJ16qd0ko25w1hUyzgQvZgPL/O1jbG2pX/p+2za/8cwLBUavZervTPzDy80agd0B8u+UiVtcT37U3J85rtz/wGLXQukLJcJKtQ9mQFIM/duDf/CP/Ywl3Wdda8Mxkv++THd/AA==">this in-browser Markdown editor</a>. For more information about Markdown see GitHub’s helpful <a href="https://guides.github.com/features/mastering-markdown/"><em>Mastering Markdown</em></a> guide.</p>
</div>
<div id="pull-requests" class="section level3">
<h3><span class="header-section-number">6.6.2</span> Pull Requests</h3>
<p>The next two features of GitHub we’re going to discuss - <strong>pull requests</strong> and <strong>forking</strong> - are what make GitHub so great. A pull request allows you to interactively compare two different branches before you merge them so you can either go ahead with the merge or provide feedback to whoever opened the pull request. Essentially a pull request allows a person to ask another person if they’re willing to incorporate changes on one branch into another branch. This social coding transaction may involve you and a collaborator, you and a stranger, or you might open a pull request on your own repository just as a method of staying organized.</p>
<p>Since I can’t guarantee that you have a collaborator I’ll show you how to open a pull request on your own repository. First in your local <code>my-first-repo</code> repository let’s switch over to the <code>update-readme</code> branch.</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> checkout update-readme</code></pre></div>
<pre><code>## Switched to branch 'update-readme'</code></pre>
<p>Let’s take a look at what’s currently on this branch:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">ls</span></code></pre></div>
<pre><code>## bernie.jpg
## toby.jpg
## file1.txt
## file2.txt
## readme.txt</code></pre>
<p>It looks like we haven’t updated this branch to be current with the <code>master</code> branch. We can easily do this by merging in the <code>master</code> branch.</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> merge master</code></pre></div>
<pre><code>## Updating 5aa94fa..2169912
## Fast-forward
## README.md | 28 ++++++++++++++++++++++++++++
## readme.txt | 4 ----
## 2 files changed, 28 insertions(+), 4 deletions(-)
## create mode 100644 README.md
## delete mode 100644 readme.txt</code></pre>
<p>Now the <code>master</code> and <code>update-readme</code> branches are identical. Let’s clean up this directory so that you can make a little personalized Markdown project. First let’s delete all of the files in this directory that we don’t really need, meaning everything except <code>README.md</code>.</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">rm</span> *.txt
<span class="fu">rm</span> *.jpg
<span class="fu">ls</span></code></pre></div>
<pre><code>## README.md</code></pre>
<p>Now that we’ve cleaned up our repository let’s open up <code>README.md</code> with <code>nano</code>. Delete everything that’s written there and write a few lines about yourself. In the block of text below you can see what I’ve written in <code>README.md</code>.</p>
<pre><code># Sean Kross
### Geography
I live in the city of Baltimore, in the state of Maryland, in the United States
of America.
### Reading
Three of my favorite books are:
- *Mindstorms* by Seymour Papert
- *Welcome to the Monkey House* by Kurt Vonnegut
- *Persepolis* by Marjane Satrapi
### Food
Last night I dreamt about eating in these restaurants:
1. Linger in Denver.
2. Azura in Jerusalem.
3. Gemma in New York City.
### Contact
The best way to get in touch with me is [on Twitter](https://twitter.com/seankross).</code></pre>
<p>Once you’ve written up a few fun things about yourself, add your changes, and make a new commit.</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> add -A
<span class="fu">git</span> commit -m <span class="st">"made readme more personal"</span></code></pre></div>
<p>Like a local Git repository, remote repositories on GitHub can have multiple branches. Let’s push this commit to the <code>update-readme</code> branch on GitHub:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> push origin update-readme</code></pre></div>
<pre><code>## Counting objects: 3, done.
## Delta compression using up to 4 threads.
## Compressing objects: 100% (3/3), done.
## Writing objects: 100% (3/3), 630 bytes | 0 bytes/s, done.
## Total 3 (delta 0), reused 0 (delta 0)
## To https://github.com/seankross/my-first-repo.git
## * [new branch] update-readme -> update-readme</code></pre>
<p>Notice that we needed to specify which remote we were pushing to since GitHub didn’t previously know about the existence of the <code>update-readme</code> branch. When you perform a <code>git push</code>, only the commits on the current branch are sent to the remote repository. That way you can create local branches that cannot be accessed from the remote repository, unless you explicitly push them to GitHub.</p>
<p>Now let’s go back to the GitHub page for our repository. On the left side of the page you should see a button that says “Branch: master.” Click on that button and a little drop-down menu should appear, as you can see below:</p>
<div class="figure">
<img src="images/branch-button.png" />
</div>
<p>Click “update-readme” in the menu in order to view the files in that branch. You should see that the <code>README.md</code> files are different! You can switch back and forth between looking at branches using this menu.</p>
<p>Now that you’ve pushed an updated branch to GitHub, let’s open a pull request. A pull request is like a guided <code>git merge</code> that is facilitated by GitHub. To start the pull request click the “New pull request” button next to the branch button (see the upper left corner of the image above). That button should take you to a page like this:</p>
<div class="figure">
<img src="images/create-pr.png" />
</div>
<p>There are a few important details on this page, so let’s go through them. First under the “Open a pull request” heading you can see the names of two branches. The branch name after “base:” shows the branch that changes are being merged into (in this case the <code>master</code> branch), and the branch name after “compare:” shows the branch that has the changes (in this case the <code>update-readme</code> branch).</p>
<p>In the text boxes below you can write a title for your pull request (the default title in this case is the name of the last commit) and you can write comments about the pull request which you can format with Markdown. If you’re collaborating with somebody else on a project it’s important to write good comments so that your collaborators know what changes you made in the branch you are requesting to merge. If you scroll down the page you can see a line-by-line comparison of the changes in the “compare” branch compared to the “base” branch. When you’ve finished going over these changes click the green “Create pull request” button in order to open the pull request. You should now see a screen like this:</p>
<div class="figure">
<img src="images/opened-pr.png" />
</div>
<p>Congratulations on opening your first pull request! Let’s take a look at what’s happening on this page. Below the title of the pull request we can see three tabs called <strong>Conversation</strong>, <strong>Commits</strong>, and <strong>Files changed</strong>. In the <strong>Conversation</strong> tab we can add comments to the pull request which can be formatted with Markdown. The <strong>Commits</strong> tab lists the commits that have been made to the “compare” branch in this pull request. Finally the <strong>Files changed</strong> tab shows the same line-by-line comparison we saw before.</p>
<p>Usually when you’re working with collaborators there’s a great deal of discussion that occurs after you open a pull request. Git commits that are pushed to the “compare” branch (<code>update-readme</code> in the case) of the GitHub repository will be reflected in a pull request even after the request has been opened. This way changes that are made as a result of the discussion can be easily incorporated. Once you’re ready go back to the <strong>Conversation</strong> tab and click the green “Merge pull request” button, then click the green “Confirm merge” button that appears. This will <code>git merge</code> the “compare” branch into the “base” branch on our remote repository. You just merged your first pull request! Now click near the top left corner of this page on the <strong><> Code</strong> tab, and you should see that the changes from the <code>update-readme</code> branch have been merged into <code>master</code>.</p>
<p>When working on a remote GitHub repository with many other folks these pull requests and merges can happen without you being involved at all if the commits affect parts of the code that you’re not working on. Still it’s important to keep your local repository up to date with the latest changes in the remote repository. Let’s go back to your terminal where you have <code>my-first-repo</code> set as the current working directory. First let’s switch to the <code>master</code> branch.</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> checkout master</code></pre></div>
<p>Now let’s update our local master branch with the commits that have been merged into the master branch on our remote repository. We can accomplish this with the command <code>git pull</code>:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="fu">git</span> pull</code></pre></div>
<pre><code>## remote: Counting objects: 1, done.
## remote: Total 1 (delta 0), reused 0 (delta 0), pack-reused 0
## Unpacking objects: 100% (1/1), done.
## From https://github.com/seankross/my-first-repo
## 2169912..b9217f6 master -> origin/master
## Updating 2169912..b9217f6
## Fast-forward
## README.md | 38 ++++++++++++++++++--------------------
## file1.txt | 0
## file2.txt | 0
## 3 files changed, 18 insertions(+), 20 deletions(-)
## delete mode 100644 file1.txt
## delete mode 100644 file2.txt</code></pre>
<p>With <code>git pull</code> Git finds the <code>master</code> branch on the <code>origin</code> remote repository and updates our local repository with the new commits. You’ve now completed the full pull request life cycle! In the <strong>Forking</strong> section of this chapter we’ll come back to discussing how GitHub super-charges pull requests in order to foster a greater coding community.</p>
</div>
<div id="pages" class="section level3">
<h3><span class="header-section-number">6.6.3</span> Pages</h3>
<p>For now we’re going to take a little detour to discuss <a href="https://pages.github.com/">GitHub Pages</a>. GitHub Pages allows you to create and host a website on GitHub using only Git and Markdown. Go back to your <code>my-first-repo</code> repository page on GitHub on click the <em>Settings</em> tab at the top. Scroll down the page until you see a box that says <strong>GitHub Pages</strong>. Then click on the drop-down menu that says <strong>None</strong>. You should see a screen like this:</p>
<div class="figure">
<img src="images/select-pages.png" />
</div>
<p>Click <em>master branch</em> and then click <em>Save</em>. Now go to the website [your-github-username].github.io/my-first-repo (in my case the address is <a href="http://seankross.github.io/my-first-repo">seankross.github.io/my-first-repo</a>) and you should see your very own website!</p>
<div class="figure">
<img src="images/my-website.png" />
</div>
<p>How cool is that!? If you want to change your new website all you need to do is edit your <code>README.md</code> then commit and push the changes! Websites like these are great for showing off projects, providing software documentation, creating online resumes, or writing a blog! GitHub pages websites can be as simple as a few Markdown documents, or if you know some web programming you can turn them into complex websites. For more information about GitHub Pages you can check out the <a href="https://pages.github.com/">documentation here</a>.</p>
</div>
<div id="forking" class="section level3">