-
Notifications
You must be signed in to change notification settings - Fork 1
/
git-training.tex
1158 lines (1034 loc) · 37.7 KB
/
git-training.tex
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
% SPDX-License-Identifier: CC-BY-NC-SA-3.0
% Copyright 2022 KUNBUS GmbH
% With work from https://git-scm.com/book/en/v2
\documentclass[aspectratio=169]{beamer}
\usepackage{minted}
\usepackage{xcolor}
\definecolor{LightGray}{gray}{0.9}
\usetheme {default}
\setbeamertemplate{navigation symbols}{}
\AtBeginSection[]{
\begin{frame}
\vfill
\centering
\begin{beamercolorbox}[sep=8pt,center,shadow=true,rounded=true]{title}
\usebeamerfont{title}\insertsectionhead\par%
\end{beamercolorbox}
\vfill
\end{frame}
}
\graphicspath{{images/}{\main/images/}}
% Title page details
\title {git training\footnote{This work is licensed under a \href{http://creativecommons.org/licenses/by-nc-sa/3.0/}{Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.}}}
\subtitle{git, workflows, github}
\author{Philipp Rosenberger}
\institute{KUNBUS GmbH}
%\date{\today}
\renewcommand{\footnotesize}{\tiny}
\newcommand{\sectiontitle}{}
\newcommand{\newsection}[1]{\renewcommand{\sectiontitle}{#1}\section{#1}}
% Image Logo
\logo{\includegraphics[width=2.5cm]{kunbus-logo.png}}
\begin{document}
\begin{frame}
% Print the title page as the first slide
\titlepage
\end{frame}
% Presentation outline
\begin{frame}{Outline}
\tableofcontents
\end{frame}
\newsection{What is a Version Control System?}
\begin{frame}{\sectiontitle}
\begin{block}{Version Control System (VCS)}
\begin{itemize}
\item Tracks changes
\item Creates a history over the changes
\item Provides traceability
\item Provides attribution
\end{itemize}
\end{block}
\end{frame}
\begin{frame}{Centralized VCS}{Centralized vs. Distributed VCS}
\begin{figure}
\centering
\includegraphics[width=\textwidth,height=0.6\textheight,keepaspectratio]{01_centralized_vcs}
\end{figure}
\end{frame}
\begin{frame}{Distributed VCS}{Centralized vs. Distributed VCS}
\begin{figure}
\centering
\includegraphics[width=\textwidth,height=0.6\textheight,keepaspectratio]{02_distributed_vcs}
\end{figure}
\end{frame}
\begin{frame}{Deltas}{Deltas vs. Snapshots}
\begin{figure}
\centering
\includegraphics[width=\textwidth,height=0.6\textheight,keepaspectratio]{deltas}
\caption{
Storing data as changes to a base version of each file\footnote{
Pro Git: 1.3 Getting Started - What is Git?
(\url{https://git-scm.com/book/en/v2/Getting-Started-What-is-Git\%3F})
}
}
\end{figure}
\end{frame}
\begin{frame}{Snapshots}{Deltas vs. Snapshots}
\begin{figure}
\centering
\includegraphics[width=\textwidth,height=0.6\textheight,keepaspectratio]{snapshots}
\caption {
Storing data as snapshots of the project over time\footnote{
Pro Git: 1.3 Getting Started - What is Git?
(\url{https://git-scm.com/book/en/v2/Getting-Started-What-is-Git\%3F})
}
}
\end{figure}
\end{frame}
\section{How does Git work?}
\begin{frame}[fragile]{Every thing is a Hash}{How does Git Work?}
\begin{minted}[bgcolor=LightGray,fontsize=\small]{text}
$ sha1sum kunbus-logo.png
c263869cf482a5d5d4262170ec242f8f13fc3def kunbus-logo.png
$ ls -sh kunbus-logo.png
352K kunbus-logo.png
\end{minted}
\begin{itemize}
\item A file is an \emph{object} with a \emph{hash} and a \emph{size}
\item Everything is identified by its hash, not only file objects
\end{itemize}
\end{frame}
\begin{frame}{Git is a Tree of Hashes}{How does Git Work?}
\begin{figure}
\centering
\includegraphics[width=\textwidth,height=0.6\textheight,keepaspectratio]{data-model-2}
\caption{
The content structure of your current Git data\footnote{
Pro Git: 10.2 Git Internals - Git Objects
(\url{https://git-scm.com/book/en/v2/Git-Internals-Git-Objects})
}
}
\end{figure}
\end{frame}
\begin{frame}{Git is a Tree of Trees of Hashes}{How does Git Work?}
\begin{figure}
\centering
\includegraphics[width=\textwidth,height=0.6\textheight,keepaspectratio]{data-model-3}
\caption{
All the reachable objects in your Git directory\footnote{
Pro Git: 10.2 Git Internals - Git Objects
(\url{https://git-scm.com/book/en/v2/Git-Internals-Git-Objects})
}
}
\end{figure}
\end{frame}
\newsection{Git Basics}
\begin{frame}[fragile]{First-Time Git Setup}{\sectiontitle}
You need to configure your identity. If you ignore this step your commits will
have a wrong author. And I will not accept anything from you in my repository
or any company repository.
\begin{minted}[bgcolor=LightGray,fontsize=\small]{text}
$ git config --global user.name "John Doe"
$ git config --global user.email [email protected]
\end{minted}
You can also configure your preferred editor and customize git behavior:
\url{https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup}
\end{frame}
\begin{frame}[fragile]{Getting a Git Repository}{\sectiontitle}
\begin{itemize}
\item Create a directory
\item Call \verb|git init| inside the directory
\end{itemize}
\begin{minted}[bgcolor=LightGray,fontsize=\small]{text}
$ mkdir my_project
$ cd my_project
$ git init
Initialized empty Git repository in /home/user/my_project/.git/
\end{minted}
\begin{itemize}
\item This creates a local repository
\item It is contained in the \verb|.git| directory under the \verb|my_project| directory
\end{itemize}
\end{frame}
\begin{frame}[fragile]{Getting a Git Repository}{\sectiontitle}
\begin{itemize}
\item With \verb|git clone| we can get a remote repository
\end{itemize}
\begin{minted}[bgcolor=LightGray,fontsize=\small]{text}
$ git clone https://github.com/libgit2/libgit2
Cloning into 'libgit2'...
remote: Enumerating objects: 119184, done.
remote: Counting objects: 100% (119184/119184), done.
remote: Compressing objects: 100% (32744/32744), done.
remote: Total 119184 (delta 84532), reused 119074 (delta 84433), pack-r...
Receiving objects: 100% (119184/119184), 61.22 MiB | 7.21 MiB/s, done.
Resolving deltas: 100% (84532/84532), done.
\end{minted}
\begin{itemize}
\item This creates the directory \verb|libgit2|
\item A git repository (\verb|.git|) is create inside the directory
\item The git repository contains a \emph{complete} copy of the remote repository
\end{itemize}
\end{frame}
\begin{frame}{Recording Changes to the Repository}{\sectiontitle}
\begin{block}{A file in your working tree can be in one (or more) of these for states}
\begin{itemize}
\item untracked
\item unmodified
\item modified
\item staged
\end{itemize}
\end{block}
\end{frame}
\begin{frame}{Recording Changes to the Repository}{\sectiontitle}
\begin{block}{untracked}
Files which are in the working tree but are not under the control of git.
They don't exist in the history. This can be new files or build artifacts
which should not be included in the git repository.
\end{block}
\begin{block}{unmodified}
Files which are under control of git. All changes have been recorded to the
history. No additional changes have been made to the files.
\end{block}
\end{frame}
\begin{frame}{Recording Changes to the Repository}{\sectiontitle}
\begin{block}{modified}
Files which are under control of git. Files that have been changed since
the last time the changes to the file have been recorded to the history.
\end{block}
\begin{block}{staged}
Files which are marked to be recorded to the history. Changes to files files
in modified stage need to be staged before they can be recorded to the
history. Also untracked files need to be staged before the can be recorded to
the history.
\end{block}
\end{frame}
\begin{frame}{Recording Changes to the Repository}{\sectiontitle}
\begin{figure}
\centering
\includegraphics[width=\textwidth,height=0.6\textheight,keepaspectratio]{lifecycle}
\caption{
The lifecycle of the status of your files\footnote{
Pro Git: 2.2 Git Basics - Recording Changes to the Repository
(\url{https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository})
}
}
\end{figure}
\end{frame}
\begin{frame}[fragile]{Recording Changes to the Repository}{\sectiontitle}
\begin{block}{Example: \ttfamily git add}
\begin{minted}[bgcolor=LightGray,fontsize=\footnotesize,breaklines]{text}
my_project$ echo "# My Project" > README.md
my_project$ git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
README.md
nothing added to commit but untracked files present (use "git add" to track)
\end{minted}
\end{block}
\end{frame}
\begin{frame}[fragile]{Recording Changes to the Repository}{\sectiontitle}
\begin{block}{Example: \ttfamily git add}
\begin{minted}[bgcolor=LightGray,fontsize=\footnotesize]{text}
my_project$ git add README.md
my_project$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: README.md
\end{minted}
\end{block}
\end{frame}
\begin{frame}[fragile]{Recording Changes to the Repository}{\sectiontitle}
\begin{block}{Example: \ttfamily git commit}
\begin{minted}[bgcolor=LightGray,fontsize=\footnotesize]{text}
my_project$ git commit
>EDITOR OPENS<
[master (root-commit) 1945062] Add initial REAMDE.md
1 file changed, 1 insertion(+)
create mode 100644 README.md
my_project$ git status
On branch master
nothing to commit, working tree clean
my_project$ ls
README.md
\end{minted}
\end{block}
\end{frame}
\begin{frame}[fragile]{Recording Changes to the Repository}{\sectiontitle}
\begin{block}{Example: Change file and commit changes}
\begin{minted}[bgcolor=LightGray,fontsize=\footnotesize]{text}
my_project$ echo -e "\nCopyright 2022 KUNBUS GmbH" >> README.md
my_project$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: README.md
no changes added to commit (use "git add" and/or "git commit -a")
my_project$ git add README.md
my_project$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: README.md
my_project$ git commit
>EDITOR OPENS<
[master c16cceb] Add copyright
1 file changed, 2 insertions(+)
\end{minted}
\end{block}
\end{frame}
\begin{frame}[fragile]{Recording Changes to the Repository}{\sectiontitle}
\begin{block}{Summary}
\begin{itemize}
\item Add new files with \verb|git add| to the staging area
\item Add changes with \verb|git add| to the staging area
\item Use \verb|git status| to check the state of your files and working tree
\item Use \verb|git commit| to record changes from the staging area to the history
\end{itemize}
\end{block}
\end{frame}
\begin{frame}[fragile]{Recording Changes to the Repository}{\sectiontitle}
\begin{block}{Exercise}
\begin{enumerate}
\item Create a local git repository
\item Create and add at least two files
\item Commit your changes to the repository
\item Make changes to one or more files
\item Add and commit the changes
\end{enumerate}
\end{block}
\end{frame}
\begin{frame}[fragile]{Viewing the Commit History}{\sectiontitle}
\begin{block}{Example: \ttfamily git log}
\begin{minted}[bgcolor=LightGray,fontsize=\footnotesize]{text}
my_project$ git log
commit c16ccebd91c1a3d4b42cd575ad2912ef671ca506 (HEAD -> master)
Author: Philipp Rosenberger <[email protected]>
Date: Thu Dec 8 13:15:00 2022 +0100
Add copyright
commit 19450627f83f4e51ad42ece86d9d2a5279bc2c23
Author: Philipp Rosenberger <[email protected]>
Date: Wed Dec 7 13:15:11 2022 +0100
Add initial REAMDE.md
Add a README.md file with just the project name as starting point
\end{minted}
\end{block}
\end{frame}
\begin{frame}[fragile]{Viewing the Commit History}{\sectiontitle}
\begin{block}{Example: \ttfamily git log --pretty=fuller}
\begin{minted}[bgcolor=LightGray,fontsize=\footnotesize]{text}
my_project$ git log --pretty=fuller
commit c16ccebd91c1a3d4b42cd575ad2912ef671ca506 (HEAD -> master)
Author: Philipp Rosenberger <[email protected]>
AuthorDate: Thu Dec 8 13:15:00 2022 +0100
Commit: Philipp Rosenberger <[email protected]>
CommitDate: Thu Dec 8 14:00:34 2022 +0100
Add copyright
commit 19450627f83f4e51ad42ece86d9d2a5279bc2c23
Author: Philipp Rosenberger <[email protected]>
AuthorDate: Wed Dec 7 13:15:11 2022 +0100
Commit: Philipp Rosenberger <[email protected]>
CommitDate: Thu Dec 8 14:00:29 2022 +0100
Add initial REAMDE.md
Add a README.md file with just the project name as starting point
\end{minted}
\end{block}
\end{frame}
\begin{frame}[fragile]{Viewing the Commit History}{\sectiontitle}
\begin{block}{Example: \ttfamily git show}
\begin{minted}[bgcolor=LightGray,fontsize=\footnotesize]{diff}
my_project$ git show 19450627f83f4e51ad42ece86d9d2a5279bc2c23
commit 19450627f83f4e51ad42ece86d9d2a5279bc2c23
Author: Philipp Rosenberger <[email protected]>
Date: Wed Dec 7 13:15:11 2022 +0100
Add initial REAMDE.md
Add a README.md file with just the project name as starting point
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..a2beefd
--- /dev/null
+++ b/README.md
@@ -0,0 +1 @@
+# My Project
\end{minted}
\end{block}
\end{frame}
\begin{frame}[fragile]{Viewing the Commit History}{\sectiontitle}
\begin{block}{Summary}
\begin{itemize}
\item List the history with \verb|git log|
\item The difference between author and committer
\item Inspect any commit form you history (or git repo) with \verb|git show|
\end{itemize}
\end{block}
\end{frame}
\begin{frame}[fragile]{Undoing Things}{\sectiontitle}
\begin{block}{Example: Change your last commit: \texttt{git commit --amend} {\small(1)}}
\begin{minted}[bgcolor=LightGray,fontsize=\footnotesize]{diff}
my_project$ vim README.md
my_project$ git diff
diff --git a/README.md b/README.md
index 7207d0d..272997d 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,3 @@
# My Project
-Copyright 2022 KUNBUS GmbH
+Copyright 2022 KUNBUS GmbH <[email protected]>
my_project$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: README.md
no changes added to commit (use "git add" and/or "git commit -a")
\end{minted}
\end{block}
\end{frame}
\begin{frame}[fragile]{Undoing Things}{\sectiontitle}
\begin{block}{Example: Change your last commit: \texttt{git commit --amend} {\small(2)}}
\begin{minted}[bgcolor=LightGray,fontsize=\footnotesize]{diff}
my_project$ git add README.md
my_project$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: README.md
my_project$ git commit --amend
>EDITOR OPENS<
[master 0e59905] Add KUNBUS copyright notice
Date: Thu Dec 8 13:15:00 2022 +0100
1 file changed, 2 insertions(+)
\end{minted}
\end{block}
\end{frame}
\begin{frame}[fragile]{Undoing Things}{\sectiontitle}
\begin{block}{Example: Change your last commit: \texttt{git commit --amend} {\small(3)}}
\begin{minted}[bgcolor=LightGray,fontsize=\footnotesize]{diff}
my_project$ git show HEAD
commit 0e59905d83e2d075098d0ea3d0ec4c4f2b45bbfc (HEAD -> master)
Author: Philipp Rosenberger <[email protected]>
Date: Thu Dec 8 13:15:00 2022 +0100
Add KUNBUS copyright notice
diff --git a/README.md b/README.md
index a2beefd..272997d 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,3 @@
# My Project
+
+Copyright 2022 KUNBUS GmbH <[email protected]>
\end{minted}
\end{block}
\end{frame}
\begin{frame}[fragile]{Undoing Things}{\sectiontitle}
\begin{block}{Example: Change your last commit: \texttt{git commit --amend} {\small(4)}}
\begin{minted}[bgcolor=LightGray,fontsize=\footnotesize]{text}
my_project$ git log
commit 0e59905d83e2d075098d0ea3d0ec4c4f2b45bbfc (HEAD -> master)
Author: Philipp Rosenberger <[email protected]>
Date: Thu Dec 8 13:15:00 2022 +0100
Add KUNBUS copyright notice
commit 19450627f83f4e51ad42ece86d9d2a5279bc2c23
Author: Philipp Rosenberger <[email protected]>
Date: Wed Dec 7 13:15:11 2022 +0100
Add initial REAMDE.md
Add a README.md file with just the project name as starting point
\end{minted}
\end{block}
\end{frame}
\begin{frame}[fragile]{Undoing Things}{\sectiontitle}
\begin{block}{Summary}
\begin{itemize}
\item Change the last commit with \verb|git commit --amend|
\item The key word \verb|HEAD| references the current (last) commit in the work tree
\end{itemize}
\end{block}
\end{frame}
\begin{frame}[fragile]{Undoing Things}{\sectiontitle}
\begin{block}{Exercise}
Use your repository from the last exercise.
\begin{enumerate}
\item List the history of you repository
\item Inspect the first/initial commit
\item Change the last commit of your history
\end{enumerate}
\end{block}
\end{frame}
\newsection{Git Branching}
\begin{frame}{Branches in a Nutshell}{\sectiontitle}
\begin{figure}
\centering
\includegraphics[width=\textwidth,height=0.6\textheight,keepaspectratio]{commit-and-tree}
\caption{
A Commit and its tree\footnote{
Pro Git: 3.1 Git Branching - Branches in a Nutshell
(\url{https://git-scm.com/book/en/v2/Git-Branching-Branches-in-a-Nutshell})
}
}
\end{figure}
\end{frame}
\begin{frame}{Branches in a Nutshell}{\sectiontitle}
\begin{figure}
\centering
\includegraphics[width=\textwidth,height=0.6\textheight,keepaspectratio]{commits-and-parents}
\caption{
Commits and their parents\footnote{
Pro Git: 3.1 Git Branching - Branches in a Nutshell
(\url{https://git-scm.com/book/en/v2/Git-Branching-Branches-in-a-Nutshell})
}
}
\end{figure}
\end{frame}
\begin{frame}[fragile]{Branches in a Nutshell}{\sectiontitle}
\begin{minted}[bgcolor=LightGray,fontsize=\footnotesize]{diff}
$ git branch testing
\end{minted}
\begin{figure}
\centering
\includegraphics[width=\textwidth,height=0.5\textheight,keepaspectratio]{two-branches}
\caption{
Two branches pointing into the same series of commits\footnote{
Pro Git: 3.1 Git Branching - Branches in a Nutshell
(\url{https://git-scm.com/book/en/v2/Git-Branching-Branches-in-a-Nutshell})
}
}
\end{figure}
\end{frame}
\begin{frame}{Branches in a Nutshell}{\sectiontitle}
\begin{figure}
\centering
\includegraphics[width=\textwidth,height=0.6\textheight,keepaspectratio]{head-to-master}
\caption{
HEAD pointing to a branch\footnote{
Pro Git: 3.1 Git Branching - Branches in a Nutshell
(\url{https://git-scm.com/book/en/v2/Git-Branching-Branches-in-a-Nutshell})
}
}
\end{figure}
\end{frame}
\begin{frame}[fragile]{Branches in a Nutshell}{\sectiontitle}
\begin{minted}[bgcolor=LightGray,fontsize=\footnotesize]{diff}
$ git checkout testing
\end{minted}
\begin{figure}
\centering
\includegraphics[width=\textwidth,height=0.5\textheight,keepaspectratio]{head-to-testing}
\caption{
HEAD points to the current branch\footnote{
Pro Git: 3.1 Git Branching - Branches in a Nutshell
(\url{https://git-scm.com/book/en/v2/Git-Branching-Branches-in-a-Nutshell})
}
}
\end{figure}
\end{frame}
\begin{frame}[fragile]{Branches in a Nutshell}{\sectiontitle}
\begin{minted}[bgcolor=LightGray,fontsize=\footnotesize]{diff}
$ vim test.rb
$ git commit -a -m 'made a change'
\end{minted}
\begin{figure}
\centering
\includegraphics[width=\textwidth,height=0.5\textheight,keepaspectratio]{advance-testing}
\caption{
The HEAD branch moves forward when a commit is made\footnote{
Pro Git: 3.1 Git Branching - Branches in a Nutshell
(\url{https://git-scm.com/book/en/v2/Git-Branching-Branches-in-a-Nutshell})
}
}
\end{figure}
\end{frame}
\begin{frame}[fragile]{Branches in a Nutshell}{\sectiontitle}
\begin{minted}[bgcolor=LightGray,fontsize=\footnotesize]{diff}
$ git checkout master
\end{minted}
\begin{figure}
\centering
\includegraphics[width=\textwidth,height=0.5\textheight,keepaspectratio]{checkout-master}
\caption{
HEAD moves when you checkout\footnote{
Pro Git: 3.1 Git Branching - Branches in a Nutshell
(\url{https://git-scm.com/book/en/v2/Git-Branching-Branches-in-a-Nutshell})
}
}
\end{figure}
\end{frame}
\begin{frame}[fragile]{Branches in a Nutshell}{\sectiontitle}
\begin{minted}[bgcolor=LightGray,fontsize=\footnotesize]{diff}
$ vim test.rb
$ git commit -a -m 'made other changes'
\end{minted}
\begin{figure}
\centering
\includegraphics[width=\textwidth,height=0.5\textheight,keepaspectratio]{advance-master}
\caption{
Divergent history\footnote{
Pro Git: 3.1 Git Branching - Branches in a Nutshell
(\url{https://git-scm.com/book/en/v2/Git-Branching-Branches-in-a-Nutshell})
}
}
\end{figure}
\end{frame}
\begin{frame}{Basic Branching and Merging}{\sectiontitle}
\begin{figure}
\centering
\includegraphics[width=\textwidth,height=0.5\textheight,keepaspectratio]{basic-branching-1}
\caption{
A simple commit history\footnote{
Pro Git: 3.2 Git Branching - Basic Branching and Merging
(\url{https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging})
}
}
\end{figure}
\end{frame}
\begin{frame}[fragile]{Basic Branching and Merging}{\sectiontitle}
\begin{minted}[bgcolor=LightGray,fontsize=\footnotesize]{diff}
$ git checkout -b iss53
\end{minted}
\begin{figure}
\centering
\includegraphics[width=\textwidth,height=0.5\textheight,keepaspectratio]{basic-branching-2}
\caption{
Creating a new branch pointer\footnote{
Pro Git: 3.2 Git Branching - Basic Branching and Merging
(\url{https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging})
}
}
\end{figure}
\end{frame}
\begin{frame}[fragile]{Basic Branching and Merging}{\sectiontitle}
\begin{minted}[bgcolor=LightGray,fontsize=\footnotesize]{diff}
$ vim index.html
$ git commit -a -m 'Create new footer [issue 53]'
\end{minted}
\begin{figure}
\centering
\includegraphics[width=\textwidth,height=0.5\textheight,keepaspectratio]{basic-branching-3}
\caption{
The \texttt{iss53} branch has moved forward with your work\footnote{
Pro Git: 3.2 Git Branching - Basic Branching and Merging
(\url{https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging})
}
}
\end{figure}
\end{frame}
\begin{frame}[fragile]{Basic Branching and Merging}{\sectiontitle}
There is an issue with your code in the \texttt{master} branch. You need to
create a hotfix for this. So we switch back to the master branch.
\begin{minted}[bgcolor=LightGray,fontsize=\footnotesize]{diff}
$ git checkout master
Switched to branch 'master'
\end{minted}
And now we create a \texttt{hotfix} branch. And create a commit to fix the broken
email address.
\begin{minted}[bgcolor=LightGray,fontsize=\footnotesize]{diff}
$ git checkout -b hotfix master
Switched to a new branch 'hotfix'
$ vim index.html
$ git commit -a -m 'Fix broken email address'
[hotfix 1fb7853] Fix broken email address
1 file changed, 2 insertions(+)
\end{minted}
\end{frame}
\begin{frame}[fragile]{Basic Branching and Merging}{\sectiontitle}
\begin{figure}
\centering
\includegraphics[width=\textwidth,height=0.5\textheight,keepaspectratio]{basic-branching-4}
\caption{
Hotfix branch based on \texttt{master}\footnote{
Pro Git: 3.2 Git Branching - Basic Branching and Merging
(\url{https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging})
}
}
\end{figure}
\end{frame}
\begin{frame}[fragile]{Basic Branching and Merging}{\sectiontitle}
Now we need to merge the \texttt{hotfix} branch into our \texttt{master} branch.
\begin{minted}[bgcolor=LightGray,fontsize=\footnotesize]{diff}
$ git checkout master
$ git merge hotfix
Updating f42c576..3a0874c
Fast-forward
index.html | 2 ++
1 file changed, 2 insertions(+)
\end{minted}
\end{frame}
\begin{frame}[fragile]{Basic Branching and Merging}{\sectiontitle}
\begin{figure}
\centering
\includegraphics[width=\textwidth,height=0.5\textheight,keepaspectratio]{basic-branching-5}
\caption{
\texttt{master} is \emph{fast-forwarded} to \texttt{hotfix}\footnote{
Pro Git: 3.2 Git Branching - Basic Branching and Merging
(\url{https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging})
}
}
\end{figure}
\end{frame}
\begin{frame}[fragile]{Basic Branching and Merging}{\sectiontitle}
Delete the \verb|hotfix| branch.
\begin{minted}[bgcolor=LightGray,fontsize=\footnotesize]{diff}
$ git branch -d hotfix
Deleted branch hotfix (3a0874c).
\end{minted}
Switch back to the \verb|iss53| branch to continue your work.
\begin{minted}[bgcolor=LightGray,fontsize=\footnotesize]{diff}
$ git checkout iss53
Switched to branch "iss53"
$ vim index.html
$ git commit -a -m 'Finish the new footer [issue 53]'
[iss53 ad82d7a] Finish the new footer [issue 53]
1 file changed, 1 insertion(+)
\end{minted}
\end{frame}
\begin{frame}[fragile]{Basic Branching and Merging}{\sectiontitle}
\begin{figure}
\centering
\includegraphics[width=\textwidth,height=0.5\textheight,keepaspectratio]{basic-branching-6}
\caption{
Work continues on \texttt{iss53}\footnote{
Pro Git: 3.2 Git Branching - Basic Branching and Merging
(\url{https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging})
}
}
\end{figure}
\end{frame}
\begin{frame}[fragile]{Basic Branching and Merging}{\sectiontitle}
The feature on the \verb|iss53| is done and can be merged into the master branch.
\begin{minted}[bgcolor=LightGray,fontsize=\footnotesize]{diff}
$ git checkout master
Switched to branch 'master'
$ git merge iss53
Merge made by the 'recursive' strategy.
index.html | 1 +
1 file changed, 1 insertion(+)
\end{minted}
\end{frame}
\begin{frame}[fragile]{Basic Branching and Merging}{\sectiontitle}
\begin{figure}
\centering
\includegraphics[width=\textwidth,height=0.5\textheight,keepaspectratio]{basic-merging-1}
\caption{
Three snapshots used in a typical merge\footnote{
Pro Git: 3.2 Git Branching - Basic Branching and Merging
(\url{https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging})
}
}
\end{figure}
\end{frame}
\begin{frame}[fragile]{Basic Branching and Merging}{\sectiontitle}
\begin{figure}
\centering
\includegraphics[width=\textwidth,height=0.5\textheight,keepaspectratio]{basic-merging-2}
\caption{
A merge commit\footnote{
Pro Git: 3.2 Git Branching - Basic Branching and Merging
(\url{https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging})
}
}
\end{figure}
\end{frame}
\begin{frame}[fragile]{Basic Branching and Merging}{\sectiontitle}
\begin{block}{Merge Conflicts}
When merging two branches which made changes to the same code it is likely you will get a merge conflict.
\begin{minted}[bgcolor=LightGray,fontsize=\footnotesize]{diff}
$ git merge iss53
Auto-merging index.html
CONFLICT (content): Merge conflict in index.html
Automatic merge failed; fix conflicts and then commit the result.
$ git status
On branch master
You have unmerged paths.
(fix conflicts and run "git commit")
Unmerged paths:
(use "git add <file>..." to mark resolution)
both modified: index.html
no changes added to commit (use "git add" and/or "git commit -a")
\end{minted}
\end{block}
\end{frame}
\begin{frame}[fragile]{Basic Branching and Merging}{\sectiontitle}
\begin{block}{Summary}
\begin{itemize}
\item Creating branches with \verb|git branch| or \verb|git checkout -b|
\item Switching between branches with \verb|git checkout|
\item Merging branches with \verb|git merge|
\item The difference between a merge commit and a fast-forward merge
\item Deleting branches with \verb|git branch -d|
\end{itemize}
\end{block}
\end{frame}
\newsection{Working with Remotes}
\begin{frame}{What is a remote (repository)?}{\sectiontitle}
\begin{itemize}
\item A remote repository is separate repository
\item It is most likely accessed over the network (e.g. ssh, https, \ldots)
\item It is configured in your local repository as \emph{remote}
\end{itemize}
\end{frame}
\begin{frame}[fragile]{What is a remote (repository)?}{\sectiontitle}
\begin{block}{\texttt{git clone}}
The simplest and most common way to configure a remote is to \emph{clone} a
remote git repository. We have already discussed this.
\begin{minted}[bgcolor=LightGray,fontsize=\footnotesize]{text}
$ git clone https://github.com/schacon/ticgit
Cloning into 'ticgit'...
remote: Reusing existing pack: 1857, done.
remote: Total 1857 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (1857/1857), 374.35 KiB | 268.00 KiB/s, done.
Resolving deltas: 100% (772/772), done.
Checking connectivity... done.
$ cd ticgit
$ git remote -v
origin https://github.com/schacon/ticgit (fetch)
origin https://github.com/schacon/ticgit (push)
\end{minted}
\end{block}
\end{frame}
\begin{frame}[fragile]{What is a remote (repository)?}{\sectiontitle}
\begin{block}{What's up with this \texttt{origin}?}
\begin{itemize}
\item When you clone a repo the remote (from where you cloned it) will be called origin
\item You can rename it as you like
\end{itemize}
\end{block}
\begin{minted}[bgcolor=LightGray,fontsize=\footnotesize]{text}
$ git remote rename origin schacon
$ git remote -v
schacon https://github.com/schacon/ticgit (fetch)
schacon https://github.com/schacon/ticgit (push)
\end{minted}
\end{frame}
\begin{frame}[fragile]{Multiple Remotes}{\sectiontitle}
\begin{block}{How to add a remote?}
You can have as many remotes as you like/need. Use \verb|git remote add| to
add a new remote:
\begin{minted}[bgcolor=LightGray,fontsize=\footnotesize]{text}
$ git remote add ilu [email protected]:iluminat23/ticgit.git
$ git remote -v
ilu [email protected]:iluminat23/ticgit.git (fetch)
ilu [email protected]:iluminat23/ticgit.git (push)
schacon https://github.com/schacon/ticgit (fetch)
schacon https://github.com/schacon/ticgit (push)
\end{minted}
\begin{itemize}
\item The first remote (\verb|ilu|) is using ssh
\item The second remote (\verb|schacon|) is using https
\end{itemize}
\end{block}
\end{frame}
\begin{frame}[fragile]{Multiple Remotes}{\sectiontitle}
\begin{block}{How to add a remote?}
When you create a local git repo it has no remotes. But you can add a remote any time.
\begin{minted}[bgcolor=LightGray,fontsize=\footnotesize]{text}
$ mkdir empty_repo
$ cd empty_repo/
$ git init
Initialized empty Git repository in /tmp/empty_repo/.git/
$ git remote -v
$ git remote add ilu [email protected]:iluminat23/example_repo.git
$ git remote -v
ilu [email protected]:iluminat23/example_repo.git (fetch)
ilu [email protected]:iluminat23/example_repo.git (push)
\end{minted}
\end{block}
\end{frame}
\begin{frame}[fragile]{Multiple Remotes}{\sectiontitle}
\begin{block}{How to synchronize the local repo?}
To get the (newest) data from a remote use \verb|git fetch|.
\begin{minted}[bgcolor=LightGray,fontsize=\footnotesize]{text}
$ mkdir ticgit && cd ticgit/
$ git init
$ git remote add ilu [email protected]:iluminat23/ticgit.git
$ git fetch ilu
remote: Enumerating objects: 1827, done.
remote: Total 1827 (delta 0), reused 0 (delta 0), pack-reused 1827
Receiving objects: 100% (1827/1827), 328.07 KiB | 1.09 MiB/s, done.
Resolving deltas: 100% (828/828), done.
From github.com:iluminat23/ticgit
* [new branch] master -> ilu/master
\end{minted}
\end{block}
\end{frame}
\begin{frame}[fragile]{Remote Branches}{\sectiontitle}
\begin{itemize}
\item Remote references are references (pointers) in your remote repositories
\item Remote-tracking branches are references to the state of remote branches
\item Remote-tracking branch names take the form \verb|<remote>/<branch>| (e.g. \verb|origin/master|)
\end{itemize}
\end{frame}
\begin{frame}[fragile]{Remote Branches}{\sectiontitle}
\begin{block}{Example}
\begin{itemize}
\item Your git server is \verb|git.ourcompany.com|
\item You cloned the repo and the remote is named \verb|origin|
\item Development happens on the \verb|master| branch
\end{itemize}
\end{block}
\end{frame}
\begin{frame}{Remote Branches}{\sectiontitle}
\begin{figure}
\centering
\includegraphics[width=\textwidth,height=0.5\textheight,keepaspectratio]{remote-branches-1}
\caption{
Server and local repositories after cloning\footnote{
3.5 Git Branching - Remote Branches
(\url{https://git-scm.com/book/en/v2/Git-Branching-Remote-Branches})
}
}
\end{figure}
\end{frame}
\begin{frame}[fragile]{Remote Branches}{\sectiontitle}
\begin{itemize}
\item You do some work on your local \verb|master|
\item Someone else does some work on the remote \verb|master|
\end{itemize}
\end{frame}
\begin{frame}{Remote Branches}{\sectiontitle}