-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
1118 lines (878 loc) · 38.2 KB
/
Copy pathindex.html
File metadata and controls
1118 lines (878 loc) · 38.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
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 PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="generator" content=
"HTML Tidy for Mac OS X (vers 31 October 2006 - Apple Inc. build 15.18.4), see www.w3.org">
<title></title>
</head>
<body>
<h1 id="git-overview">Git: Overview</h1>
<p>(<em>Note: GitHub lets you host (static) webpages for all of
your projects, for free. The <a href=
"http://matthewwolff.github.io/git_workshop/">webpage</a>
associated with this project is just an HTML document that I
generated from the README using <a href=
"https://pandoc.org/"><code>pandoc</code></a></em>.)</p>
<hr>
<h3 id="before-starting">Before starting:</h3>
<ul>
<li>Download <a href="https://desktop.github.com/">Github
Desktop</a></li>
<li>Join <a href="https://github.com/join">GitHub</a> by
creating an account
<ul>
<li>Use a professional-enough name, since you’ll
typically include this in your résumé</li>
</ul>
</li>
</ul>
<hr>
<h2 id="what-is-version-control">What is Version Control?</h2>
<p>Imagine you’re working on a paper CancerEvolution.docx and
you re-write a section but you’re not sure if you want to keep
it. Therefore, you “Save As” under
“CancerEvolutionRewrite.docx”. As you’re working on this
you end up re-writing another section and “Save As” to create
a slightly different copy. Or maybe you just create draft after
draft and want to have different versions for later. You’re
essentially creating different version of the same document and
manually organizing them on your desktop! Not very effective
though.</p>
<p>Take this up a level. We’re developing some bioinformatic
sequencing software. Because we’re good developers, we write
modular code and have many small files of code that we can re-use
across the application. As we try out new algorithms, these files
change and improve—but imagine trying to just send around the
latest copy of these files or upload them all to Google
drive—what if someone overwrites a copy of new changes with
their own, older changes, and it breaks everything? We need
stronger version control!</p>
<h2 id="what-is-git">What is Git?</h2>
<p>A version control system for code! Gone are the days of
“FinalPaperDraft.docx”, “FinalPaperDraftFinal.docx”,
“FinalPaperDraftFinalFinal.docx”.</p>
<blockquote>
<p>“By far, the most widely used modern version control
system in the world today is Git. Git is a mature, actively
maintained open source project originally developed in 2005 by
Linus Torvalds, the famous creator of the Linux operating
system kernel. A staggering number of software projects rely on
Git for version control, including commercial projects as well
as open source.”</p>
</blockquote>
<p>It’s extremely useful for tracking and undoing changes to
your code over time, as well as sharing your code with
others.</p>
<h2 id="what-is-github">What is GitHub?</h2>
<p>It’s a online platform that lets you store and version
control your code. It’s built around Git. There are others like
it, such as GitLab and BitBucket.</p>
<h2 id="so-whats-the-meaningful-difference-between-them">So
what’s the meaningful difference between them?</h2>
<p>Good question. Git exists purely on the command line, and is
maintained independently from these platforms. You don’t need
to know the command line to use GitHub or GitLab, you just need
to understand what version control is (and how to
copy-paste)!</p>
<h2 id="how-to-use-github">How to use GitHub?</h2>
<p>There are a few different ways!</p>
<ol type="1">
<li>Their Website – <a href=
"http:/github.com">Github.com</a><br>
<img src="./images/create_github_repo.png" alt=
"Creating a GitHub repo from GitHub Website" width="400"></li>
<li>The desktop app – <a href=
"https://desktop.github.com/">Github Desktop</a><br>
<img src="./images/github_desktop.png" alt=
"Creating a GitHub repo from GitHub Desktop" width="400"></li>
<li>The command line – <code>hub</code> – <code>brew
install hub</code><br>
<img src="./images/github_cli.png" alt=
"Creating a GitHub repo from CLI" width="400">
<ul>
<li>the only* thing you can’t do with standalone
<code>git</code> is create repositories</li>
</ul>
</li>
<li>An IDE like Atom! (GitHub integration)<br>
<img src="./images/atom_github_support.png" alt=
"Creating a GitHub repo from Atom" width="400"></li>
</ol>
<p>As a note, being a student gets you a <a href=
"https://education.github.com/pack">premium version (Github
Student Dev pack)</a> of Github for free</p>
<blockquote>
<p>It includes everything in GitHub Free, unlimited
collaborators for private repositories, and advanced code
review tools for private and public repositories.</p>
</blockquote>
<p>Not only is it good for storing code and versioning it, it
also is excellent for sharing your work. As you navigate through
various pages on GitHub, you’ll find there is often a small
writeup on some pages called the “README.md”. Whenever GitHub
finds a file called README in a repository or folder of a
repository, it will display that for you when you’re viewing
it.</p>
<p>That little document often contains instructions to compile
their code, information about the different parameters it takes,
and even some examples! We’ll revisit this later.</p>
<hr>
<h1 id="git-concepts">Git Concepts</h1>
<h2 id="the-repository">The Repository</h2>
<ul>
<li>When you are working on a project and want to use version
control, you need to first create a repository (“repo”) for
it</li>
<li>You need to interface with Github for this (or install the
<code>hub</code> command)</li>
<li>It can be public or private</li>
<li>The repository is where you’ll send your updates</li>
</ul>
<h3 id="cloning">Cloning</h3>
<p>When you want to grab someone’s repo, you don’t have to
just download the current code. You can <code>git clone</code>
the repo, which will give you an exact copy of its current
state.</p>
<h2 id="commits">Commits</h2>
<ul>
<li>When you make changes, you need to submit them to be
saved</li>
<li>You need to specify which changes you want to save!
<ul>
<li>You might have various things that you’re working on,
and only finished one of them that you want to commit</li>
</ul>
</li>
<li>You must “git add” the files that you want to
“save”</li>
<li>A commit is like a “soft-save” because it’s only
local
<ul>
<li>this can be nice—you don’t always have an internet
connection</li>
</ul>
</li>
<li>You need to publish your commits to make them global and
visible to others!</li>
</ul>
<h2 id="pushing-pulling">Pushing, Pulling</h2>
<p>This is how we publish and retrieve changes!</p>
<p>You push your local changes out to the repo, and then others
can pull them in. Sometimes you’ve edited the same thing as
someone else, and Git can’t figure out how to automatically
combine them—this is when you’ll need to decide what to keep
and what to toss. Situations like this can be frustrating when
you’re working with other people, so sometimes it’s nice to
have your own git workspace.</p>
<h2 id="branching">Branching</h2>
<p>Want to start adding something new but don’t want to
interfere with the stable code? Time to start a new branch! By
default, you’re on the “master” branch.</p>
<div class="sourceCode" id="cb1">
<pre class="sourceCode bash">
<code class="sourceCode bash"><a class="sourceLine" id="cb1-1"
title="1" name="cb1-1"><span class="op">></span> <span class=
"fu">git</span> checkout -b dev_branch</a>
<a class="sourceLine" id="cb1-2" title="2" name=
"cb1-2"><span class="ex">Switched</span> to a new branch <span class="st">'dev_branch'</span></a></code>
</pre>
</div>
<p>Branches are useful for developing new features in isolation.
Creating a new branch creates a copy of the old branch, but now
you can grow it separately. When you’re done, you can splice
that branch back into the main tree!</p>
<p>Here’s what it looks like in GitHub Desktop:</p>
<p><img src="./images/new_branch.png" width="400"></p>
<h2 id="merging">Merging</h2>
<p>What is this splicing exactly? It’s the “merge”
operation. Merging is best done when there aren’t conflicts
between the new cold and the old code, but Git helps you handle
conflicts when they arise.</p>
<p>This is one of the main strengths of GitHub—it’s very good
at automatically merging when it can, and otherwise pointing out
where the “merge conflicts” are, i.e., the places where you
need to tell it what code to keep. Let’s do a quick
example:</p>
<div class="sourceCode" id="cb2">
<pre class="sourceCode bash">
<code class="sourceCode bash"><a class="sourceLine" id="cb2-1"
title="1" name="cb2-1"><span class="bu">echo</span> <span class=
"st">"original file contents"</span> <span class=
"op">></span> my_file</a>
<a class="sourceLine" id="cb2-2" title="2" name=
"cb2-2"><span class="fu">git</span> add my_file</a>
<a class="sourceLine" id="cb2-3" title="3" name=
"cb2-3"><span class="fu">git</span> commit -m <span class=
"st">"added a new file"</span></a>
<a class="sourceLine" id="cb2-4" title="4" name=
"cb2-4"><span class="fu">git</span> push origin master</a></code>
</pre>
</div>
<p>Okay! We made some code.</p>
<div class="sourceCode" id="cb3">
<pre class="sourceCode bash">
<code class="sourceCode bash"><a class="sourceLine" id="cb3-1"
title="1" name="cb3-1"><span class=
"fu">git</span> checkout -b dev_branch <span class=
"co"># swap to a new branch for dev</span></a>
<a class="sourceLine" id="cb3-2" title="2" name=
"cb3-2"><span class="bu">echo</span> <span class=
"st">"a newly rewritten file"</span> <span class=
"op">></span> my_file</a>
<a class="sourceLine" id="cb3-3" title="3" name=
"cb3-3"><span class="bu">echo</span> <span class=
"st">"a cool change"</span> <span class=
"op">>></span> my_file</a>
<a class="sourceLine" id="cb3-4" title="4" name=
"cb3-4"><span class="fu">git</span> add my_file</a>
<a class="sourceLine" id="cb3-5" title="5" name=
"cb3-5"><span class="fu">git</span> commit -m <span class=
"st">"rewrote first part, added more"</span></a>
<a class="sourceLine" id="cb3-6" title="6" name=
"cb3-6"><span class="fu">git</span> push origin dev_branch</a></code>
</pre>
</div>
<p>Now we have a dev branch with some new code. Could we merge
this? Why or why not?</p>
<p>(yes! we could. dev changes would overwrite master. but
let’s hold off on merging back in)</p>
<p>Further:</p>
<div class="sourceCode" id="cb4">
<pre class="sourceCode bash">
<code class="sourceCode bash"><a class="sourceLine" id="cb4-1"
title="1" name="cb4-1"><span class=
"fu">git</span> checkout master</a>
<a class="sourceLine" id="cb4-2" title="2" name=
"cb4-2"><span class="bu">echo</span> <span class=
"st">"a newer change"</span> <span class=
"op">>></span> my_file</a>
<a class="sourceLine" id="cb4-3" title="3" name=
"cb4-3"><span class="fu">git</span> add my_file</a>
<a class="sourceLine" id="cb4-4" title="4" name=
"cb4-4"><span class="fu">git</span> commit -m <span class=
"st">"a newer change"</span></a>
<a class="sourceLine" id="cb4-5" title="5" name=
"cb4-5"><span class="fu">git</span> push origin master</a></code>
</pre>
</div>
<p>So what now? Can we merge? There’s an even newer change on
Master that an overwrite would lose…</p>
<h2 id="pull-requests">Pull Requests</h2>
<p>When you want to want to merge branches, you create a pull
request. This is how GitHub handles merges (and you’ll find
that command line Git isn’t very fun to do merges with when
there are conflicts).</p>
<p>Let’s hop on GitHub and see if we can do our branch merge
from before:</p>
<ul>
<li><img src="./images/new_change.png" alt="new change" width=
"500"></li>
<li><img src="./images/cant_merge.png" alt="can't merge" width=
"500"></li>
<li><img src="./images/made_pull_request.png" alt=
"pull request" width="500"></li>
<li><img src="./images/resolve_conflict.png" alt="resolve"
width="500"></li>
<li>To resolve the merge conflict, you’ll need to get rid of
the “<<<<<” and “>>>>>”
symbols—they communicate which code belongs to which
branch.</li>
<li><img src="./images/resolved.png" alt="resolved" width=
"500"></li>
<li><img src="./images/ready_to_merge.png" alt="ready to merge"
width="500"></li>
</ul>
<h2 id="forking">Forking</h2>
<p>Let’s say you find a great package on GitHub that fits your
use-case, but it’s written in Python 2 and has a few bugs.
Let’s say that the owner of this package is pretty busy. So
what do you do? We fix it our self and then make a pull
request!</p>
<p>If you just clone someone’s repo, you’ll run into trouble
when you try to push—you don’t have permission! Therefore,
let’s fork it. On GitHub, this will create a copy of the repo
under <em>your account</em>. Even if the owner deletes the
original repo, you still have yours. Additionally, it’s easy to
create a pull request from your fork of their repo!</p>
<p><img src="./images/forking.png" width="800"></p>
<h3 id="forking-vs.-branching">Forking vs. Branching</h3>
<p>These are both ways of adding on to the main code. There are
some philosophical differences and Git-level differences between
them.</p>
<ul>
<li>Both can be used for pull requests</li>
<li>Both will create a copy of the code</li>
<li>Forking creates the copy under your account</li>
<li>Branching creates a new branch under the original code
(need permission)</li>
</ul>
<h2 id="so-these-are-all-words-but-can-you-give-an-analogy">So
these are all words, but can you give an analogy?</h2>
<p>I think it all comes together like growing a
<strong>tree</strong>. All together, it’s a gradual process
where you can curate designs and shapes with the wood. You can
keep the blinds closed or let specific people into your
house!</p>
<p><strong>A Bed with Soil</strong>: Having a GitHub or GitLab
account is having a place to grow your plant. It’s your
soil.</p>
<p><strong>A Seed</strong>: Creating the repo is like planting a
seed—now you can watch it grow.</p>
<p><strong>Taking up Nutrients…</strong>: Adding changes to
your files! These are what you need to grow the project.</p>
<p><strong>Growing Taller</strong>: Committing and pushing those
changes to your project grows it. Commit after commit, the
project grows bigger.</p>
<p><strong>Branching</strong>: Very literal here. You’re
growing out a new branch from the trunk. The trunk will continue
to be the main part of the tree, but the branch can grow
separately.</p>
<p><strong>Splicing A Branch Back In</strong>: Merging! You’re
reintroducing a branch that previously diverged. Now it’s part
of the main tree again and brought back some changes with it.</p>
<p>This metaphor falls apart a bit once you start factoring in
other people. For example, what exactly is a merge conflict on a
bonsai tree? What is rebasing? There’s probably a joke about
<code>cherry-pick</code>ing here (a surprisingly useful git
command). But it’s still a useful starting analogy.</p>
<hr>
<h2 id="what-is-it-under-the-hood">What Is It Under The
Hood?</h2>
<p>Complex and abstract. It’s essentially a giant python
dictionary with a few different types of objects in it (tree
objects, commit objects, and blobs). At the same time, it holds
within it a graph structure. Most people use it for years and
years without ever bothering with what’s going on underneath
and, honestly, knowing how it is implemented won’t drastically
improve your ability to work with it.</p>
<hr>
<h1 id="example">Example</h1>
<p>Let’s create a repository!</p>
<ol type="1">
<li>You need to have a GitHub account</li>
<li>You need to have GitHub Desktop installed</li>
</ol>
<p>So let’s get started! GitHub has a few cute features with
repos. Whenever you’re looking at a repo, if there’s a
document named “README.*”, it will be displayed! The most
common format is <a href=
"https://www.markdownguide.org/basic-syntax/">Markdown</a>, which
uses the extension “*.md”. It’s considered good practice to
always include a README in the root of your repo with information
about it, such as instructions on using it.</p>
<p>GitHub also has a few repository names that it can treat
differently. For example, if you name a repo
“[username].github.io”, GitHub will actually create a new
address for you there, and you can create your own small, static
website! Try visiting <a href=
"https://matthewwolff.github.io">matthewwolff.github.io</a>!
Today, however, we’re going to create a different kind of
specially named repo.</p>
<ol type="1">
<li>Open GitHub desktop</li>
<li>Create a new (local) repository<br>
<img src="./images/create_new_repo.png" width="400">
<ul>
<li>ctrl-N or CMD-N</li>
<li>The name will be your github username</li>
<li>Initialize it with a README
<ul>
<li>what is a readme?</li>
<li>what is markdown?</li>
</ul>
</li>
</ul>
</li>
<li>Publish your repository
<ul>
<li>Make sure it’s public!</li>
<li>There’s already one automatic commit to it</li>
</ul>
</li>
<li>Go to <a href="https://github.com">GitHub</a> on your
profile</li>
<li>Enable this “special” repo so others can see it!</li>
<li>Go back to your files. Change the README.
<ul>
<li>You now have a local repo. Let’s change the README to
a small intro for your github account. Mine is
below!<br></li>
</ul>
<div class="sourceCode" id="cb5">
<pre class="sourceCode md">
<code class="sourceCode markdown"><a class="sourceLine" id="cb5-1"
title="1" name="cb5-1"><span class="fu"># Hey! 👻</span></a>
<a class="sourceLine" id="cb5-2" title="2" name=
"cb5-2">* <span class=
"fl">UW ➡️ Computer Science, Genetics & Genomics</span></a>
<a class="sourceLine" id="cb5-3" title="3" name=
"cb5-3"><span class="fl">* CMU ➡️ Computational 🅱️iology, Data Science</span></a>
<a class="sourceLine" id="cb5-4" title="4" name="cb5-4"></a>
<a class="sourceLine" id="cb5-5" title="5" name=
"cb5-5"><span class="al"></span></a>
<a class="sourceLine" id="cb5-6" title="6" name=
"cb5-6"><span class="al"></span></a></code>
</pre>
</div>
</li>
<li>Commit and Push!</li>
<li>
<p>Go to <a href="https://github.com">GitHub</a> on your
profile again</p>
<p><img src="./images/github_profile.png" width="1000"></p>
</li>
</ol>
<hr>
<h1 id="making-a-pull-request">Making a Pull Request</h1>
<ol type="1">
<li>Create a new branch using GitHub desktop</li>
<li>Make some changes
<ul>
<li>Commit them! Push them to origin!</li>
</ul>
</li>
<li>Create a pull request! (will open Github)</li>
<li>Merge the pull request</li>
<li>Profit</li>
</ol>
<p><img src="./images/new_branch.png" width="800"> <img src=
"./images/push_to_origin.png" width="800"> <img src=
"./images/create_pull_request.png" width="800"> <img src=
"./images/open_pull_request.png" width="800"> <img src=
"./images/merge_pull_request.png" width="800"> <img src=
"./images/done.png" width="800"> <img src=
"./images/delete_branch.png" width="800"></p>
<hr>
<h2 id="gitignore">.gitignore</h2>
<p>This deserves it’s own little section, because you’ll
typically want to use these. Generally you want to be careful
about blindly adding folders in Git. Why? Because there’s
probably some big or sensitive files in them somewhere that you
don’t want to upload.</p>
<p>But adding things manually is so tedious… what if we could
just specify what we want to ignore?</p>
<p>Enter <code>.gitignore</code>. This is a special file (at the
root of your repo) that git checks to remember what NOT to
consider when it’s checking what you’ve changed. It also
prevents certain files from being added when you add entire
directories. It’s very useful when you don’t want to upload
large data files, secret credentials, or small config files
created by your IDE!</p>
<h4 id=
"gitignore.io---very-useful-for-autogenerating-this-for-certain-platformslanguagestools">
<a href="https://gitignore.io">gitignore.io</a> - very useful for
autogenerating this for certain platforms/languages/tools</h4>
<hr>
<h1 id="git-commands">Git Commands</h1>
<h2 id="creation-git-clone">Creation: <code>git clone</code></h2>
<p>If you create your repo on GitHub first, you can copy the url
and use it with <code>git clone</code></p>
<div class="sourceCode" id="cb6">
<pre class="sourceCode bash">
<code class="sourceCode bash"><a class="sourceLine" id="cb6-1"
title="1" name="cb6-1"><span class="op">></span> <span class=
"fu">git</span> clone https://github.com/MatthewWolff/.sandbox</a>
<a class="sourceLine" id="cb6-2" title="2" name=
"cb6-2"><span class="ex">Cloning</span> into <span class=
"st">'.sandbox'</span>...</a>
<a class="sourceLine" id="cb6-3" title="3" name=
"cb6-3"><span class="ex">remote</span>: Enumerating objects: 25, done.</a>
<a class="sourceLine" id="cb6-4" title="4" name=
"cb6-4"><span class="ex">remote</span>: Counting objects: 100% (25/25), <span class="kw">done</span><span class="ex">.</span></a>
<a class="sourceLine" id="cb6-5" title="5" name=
"cb6-5"><span class="ex">remote</span>: Compressing objects: 100% (14/14), <span class="kw">done</span><span class="ex">.</span></a>
<a class="sourceLine" id="cb6-6" title="6" name=
"cb6-6"><span class="ex">remote</span>: Total 25 (delta 2), <span class="ex">reused</span> 20 (delta 1), <span class="ex">pack-reused</span> 0</a>
<a class="sourceLine" id="cb6-7" title="7" name=
"cb6-7"><span class="ex">Unpacking</span> objects: 100% (25/25), <span class="kw">done</span><span class="ex">.</span></a>
<a class="sourceLine" id="cb6-8" title="8" name=
"cb6-8"><span class="op">></span></a></code>
</pre>
</div>
<h2 id="creation-git-init-and-git-remote">Creation: <code>git
init</code> and <code>git remote</code></h2>
<p>This is how you create project locally if you already have
existing code! You can copy the URL of the GitHub repo you
created:</p>
<div class="sourceCode" id="cb7">
<pre class="sourceCode bash">
<code class="sourceCode bash"><a class="sourceLine" id="cb7-1"
title="1" name="cb7-1"><span class=
"fu">git</span> init <span class="co"># create the .git folder</span></a>
<a class="sourceLine" id="cb7-2" title="2" name=
"cb7-2"><span class="fu">git</span> remote -v <span class=
"co"># you have nowhere to send your changes!</span></a>
<a class="sourceLine" id="cb7-3" title="3" name=
"cb7-3"><span class="fu">git</span> remote add origin https://github.com/MatthewWolff/.sandbox</a>
<a class="sourceLine" id="cb7-4" title="4" name=
"cb7-4"><span class="fu">git</span> remote -v <span class=
"co"># origin is now set!</span></a></code>
</pre>
</div>
<h2 id="git-status"><code>git status</code></h2>
<p>Git will automatically evaluate which files have been changed,
created, or deleted, and will then give you a quick report</p>
<div class="sourceCode" id="cb8">
<pre class="sourceCode bash">
<code class="sourceCode bash"><a class="sourceLine" id="cb8-1"
title="1" name="cb8-1"><span class="op">></span> <span class=
"fu">git</span> status</a>
<a class="sourceLine" id="cb8-2" title="2" name=
"cb8-2"><span class="ex">On</span> branch master</a>
<a class="sourceLine" id="cb8-3" title="3" name="cb8-3"></a>
<a class="sourceLine" id="cb8-4" title="4" name=
"cb8-4"><span class="ex">No</span> commits yet</a>
<a class="sourceLine" id="cb8-5" title="5" name="cb8-5"></a>
<a class="sourceLine" id="cb8-6" title="6" name=
"cb8-6"><span class="ex">Untracked</span> files:</a>
<a class="sourceLine" id="cb8-7" title="7" name=
"cb8-7"> <span class="kw">(</span><span class=
"ex">use</span> <span class=
"st">"git add [file]..."</span> to include in what will be committed<span class="kw">)</span></a>
<a class="sourceLine" id="cb8-8" title="8" name="cb8-8"></a>
<a class="sourceLine" id="cb8-9" title="9" name=
"cb8-9"> <span class="ex">README.md</span></a>
<a class="sourceLine" id="cb8-10" title="10" name=
"cb8-10"> <span class="ex">images/</span></a>
<a class="sourceLine" id="cb8-11" title="11" name=
"cb8-11"> <span class="ex">index.html</span></a>
<a class="sourceLine" id="cb8-12" title="12" name="cb8-12"></a>
<a class="sourceLine" id="cb8-13" title="13" name=
"cb8-13"><span class=
"ex">nothing</span> added to commit but untracked files present (use <span class="st">"git add"</span> to track)</a></code>
</pre>
</div>
<h2 id="git-add---all"><code>git add --all</code></h2>
<p>A nice short-hand to add all the files at once! It’s
recursive, so be careful</p>
<h2 id="git-commit--m-my-message"><code>git commit -m "my
message"</code></h2>
<p>It’s important to have a descriptive message, especially if
you’re working with other people. Saying “Fixed bug”
isn’t very useful!</p>
<h2 id="git-push"><code>git push</code></h2>
<p>Git is decentralized. Your repository is local until you make
it global. Use <code>git push</code> to send your changes off to
the repository</p>
<h2 id="git-pull"><code>git pull</code></h2>
<p>If you’re working on a project on a lab computer and a home
computer and making changes from both, pull the changes that you
pushed from the other computer! Also, if you’re working with
other people you want to make sure you have the latest
changes</p>
<h2 id="git-checkout-filename"><code>git checkout
[filename]</code></h2>
<p>This one is good to know. If you want to undo all the changes
that you made to a file, you can just “checkout” that file
from the last commit. Very good for undoing mistakes or
accidental changes</p>
<h2 id="all-together">All Together</h2>
<div class="sourceCode" id="cb9">
<pre class="sourceCode bash">
<code class="sourceCode bash"><a class="sourceLine" id="cb9-1"
title="1" name="cb9-1"><span class="bu">echo</span> <span class=
"st">"i have created a repo on GitHub with this project name"</span></a>
<a class="sourceLine" id="cb9-2" title="2" name=
"cb9-2"><span class="fu">mkdir</span> my_project <span class=
"kw">&&</span> <span class="bu">cd</span> my_project</a>
<a class="sourceLine" id="cb9-3" title="3" name=
"cb9-3"><span class="fu">git</span> init</a>
<a class="sourceLine" id="cb9-4" title="4" name=
"cb9-4"><span class="fu">git</span> remote add origin https://github.com/matthewwolff/my_project</a>
<a class="sourceLine" id="cb9-5" title="5" name=
"cb9-5"><span class="fu">git</span> status</a>
<a class="sourceLine" id="cb9-6" title="6" name="cb9-6"></a>
<a class="sourceLine" id="cb9-7" title="7" name=
"cb9-7"><span class="bu">echo</span> <span class=
"st">"# My Project"</span> <span class=
"op">>></span> README.md <span class=
"co"># create a change</span></a>
<a class="sourceLine" id="cb9-8" title="8" name="cb9-8"></a>
<a class="sourceLine" id="cb9-9" title="9" name=
"cb9-9"><span class="fu">git</span> add --all</a>
<a class="sourceLine" id="cb9-10" title="10" name=
"cb9-10"><span class="fu">git</span> commit -m <span class=
"st">"initial commit"</span></a>
<a class="sourceLine" id="cb9-11" title="11" name=
"cb9-11"><span class="fu">git</span> push <span class=
"co"># publish it</span></a>
<a class="sourceLine" id="cb9-12" title="12" name="cb9-12"></a>
<a class="sourceLine" id="cb9-13" title="13" name=
"cb9-13"><span class="fu">rm</span> README.md <span class=
"co"># oops</span></a>
<a class="sourceLine" id="cb9-14" title="14" name=
"cb9-14"><span class=
"fu">git</span> checkout README.md <span class="co"># all better</span></a></code>
</pre>
</div>
<hr>
<h1 id="best-practices">Best Practices</h1>
<p>Using Git correctly helps future you and your teammates</p>
<ul>
<li>Make clean, single-purpose commits</li>
<li>Don’t use <code>--force</code>
<ul>
<li>it will overwrite other’s changes, and you only need
to use it when you’ve done something bad</li>
</ul>
</li>
<li>Write meaningful commit messages</li>
<li>Don’t alter published history
<ul>
<li>I do this A LOT, but only on my personal projects</li>
<li>You can re-write git history, but if anyone else is
working with your code, it really screws them up and they
will have to deal with a lot of errors when trying to merge
or pulling</li>
<li>Some companies use <em>advanced</em> git configurations
to prevent this (look into “git hooks”)</li>
</ul>
</li>
<li>Don’t commit generated files
<ul>
<li>if your code generates files every time you run it,
don’t bother committing those!</li>
</ul>
</li>
<li>Don’t commit really big files that change often
<ul>
<li>your <code>.git/</code> folder will be bloated and
you’ll have to use a tool like <a href=
"https://rtyley.github.io/bfg-repo-cleaner/"><code>bfg</code></a>
to clean it out</li>
</ul>
</li>
<li>Don’t commit sensitive information
<ul>
<li>This goes without saying, but if you submit passwords
or API keys, you’ll need to edit the git history</li>
<li>You can’t just submit a new commit, because someone
could look at older commits</li>
<li>Use <a href=
"https://rtyley.github.io/bfg-repo-cleaner/"><code>bfg</code></a>
to fix this mistake</li>
</ul>
</li>
</ul>
<hr>
<h1 id="closing">Closing</h1>
<p>At this point, you should feel like you know how to add and
commit changes, as well as have a light grasp on what you
shouldn’t do when using Git.</p>
<hr>
<h1 id="appendix">Appendix</h1>
<h3 id="git-integration">Git Integration</h3>
<p>Almost every IDE (Integrated Developer Environment) that you
use has git integration! For instance, Atom, IntelliJ, GoLand.
It’s like a miniature GitHub desktop, except it’s not
specific to GitHub!</p>
<h3 id="are-there-other-version-control-systems">Are there other
Version Control systems?</h3>
<p>Yes, there are actually a few, and the following list is not
exhaustive:</p>
<ul>
<li>Git
<ul>
<li>Created in 2005 and currently the most used</li>
<li>Decentralized, so you don’t need a central
server</li>
<li>Can have local changes and use it completely
offline</li>
<li>Written in C</li>
</ul>
</li>
<li>Mercurial
<ul>
<li>Decentralized, like Git</li>
<li>Doesn’t have a Merge feature (some people really
don’t like that)</li>
<li>Written in Python</li>
<li>Was competing with Git to be used by Linux Kernel,
ultimately lost</li>
<li>Easier to learn than Git, with better
documentation</li>
</ul>
</li>
<li>CVS [Concurrent Versions System]
<ul>
<li>a dinosaur from the 80’s</li>
<li>Centralized, runs on your server</li>
<li>You “check out” code, make changes, then “check
in”</li>
</ul>
</li>
<li>SVN [Apache SubVersioN]
<ul>
<li>A better version of CVS</li>
<li>Centralized</li>
<li>Not <em>totally</em> uncommon</li>
</ul>
</li>
</ul>
<h3 id="cool-commands">Cool Commands</h3>
<p>I have dozens of bash aliases set up for certain git commands.
It helps to not need to remember or worry about certain things,
like which branch you’re on.</p>
<ul>
<li>
<code>git whatchanged -p --abbrev-commit
--pretty=medium</code>
<ul>
<li>HEAVEN SENT. This lets you view a <code>diff</code> of
the past commits</li>
<li>extremely useful to jog your memory on what was changed
in the last commit</li>
</ul>
</li>
<li>
<code>git diff</code>
<ul>
<li>this shows the you the difference between your current
files and the last commit. Only more useful than the above
when you haven’t committed yet</li>
</ul>
</li>
<li>
<code>git reset</code>
<ul>
<li>This will do a <strong>soft</strong> reset and unstage
any changes</li>
<li>Useful for when you accidentally <code>git add</code> a
file</li>
</ul>
</li>
<li>
<code>git log --oneline --decorate --graph</code>
<ul>
<li>see a brief, visual summary of the branch
histories</li>
</ul>
</li>
<li>
<code>git status -s</code>
<ul>
<li>see which uncommitted files have changed!</li>
</ul>
</li>
<li>
<code>git [push/pull] origin "$(git_current_branch)"</code>
<ul>
<li>this uses a built-in git method to grab your current
branch</li>
<li>most useful when you’re working with branches</li>
</ul>
</li>
<li>
<code>git stash</code> and <code>git stash pop</code>
<ul>
<li>When you’re switching between branches and you
don’t want to commit your changes yet, you can simply
stash them. When you switch back to the branch, use
<code>git stash pop</code> to pop them off the stash stack
(data structures!)</li>
</ul>
</li>
<li>
<code>git cherry-pick</code>
<ul>
<li>This let’s you pluck a single commit from a different
branch and add it to your current branch</li>