% Created 2021-03-30 Tue 21:12
% Intended LaTeX compiler: pdflatex
\documentclass[presentation]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage{hyperref}
% features: (embed-files custom-font microtype maths .custom-maths-font acronym underline par-sep alegreya-typeface beamer image emoji engraved-code-setup engraved-code)

  \usepackage[main,include]{embedall}
  \IfFileExists{./\jobname.org}{\embedfile[desc=The original file]{\jobname.org}}{}
  
\usepackage[osf]{Alegreya}
\usepackage{AlegreyaSans}
\usepackage[scale=0.88]{sourcecodepro}

\usepackage[activate={true,nocompatibility},final,tracking=true,kerning=true,spacing=true,factor=2000]{microtype}

\usepackage[nofont]{bmc-maths}
\usepackage[varbb]{newpxmath}

\newcommand{\acr}[1]{\protect\textls*[110]{\scshape #1}}
\newcommand{\acrs}{\protect\scalebox{.91}[.84]{\hspace{0.15ex}s}}
\usepackage[normalem]{ulem}
\setlength{\parskip}{\baselineskip}
\setlength{\parindent}{0pt}

\usepackage{graphicx}
\newcommand\emoji[1]{\raisebox{-0.3ex}{\includegraphics[height=1.8ex]{/home/tec/.emacs.d/.local/etc/emojis/twemoji-v2/#1}}}

  \usepackage{fvextra}
  \fvset{
    commandchars=\\\{\},
    highlightcolor=white!95!black!80!blue,
    breaklines=true,
    breaksymbol=\color{white!60!black}\tiny\ensuremath{\hookrightarrow}}
  \renewcommand\theFancyVerbLine{\footnotesize\color{black!40!white}\arabic{FancyVerbLine}}
  
  % TODO have code boxes keep line vertical alignment
  \usepackage[breakable,xparse]{tcolorbox}
  \DeclareTColorBox[]{Code}{o}%
  {colback=white!97!black, colframe=white!94!black,
    fontupper=\color{EFD}\footnotesize,
    IfNoValueTF={#1}%
    {boxsep=2pt, arc=2.5pt, outer arc=2.5pt,
      boxrule=0.5pt, left=2pt}%
    {boxsep=2.5pt, arc=0pt, outer arc=0pt,
      boxrule=0pt, leftrule=1.5pt, left=0.5pt},
    right=2pt, top=1pt, bottom=0.5pt,
    breakable}
  
\definecolor{EFD}{HTML}{383a42}
\definecolor{EFk}{HTML}{e45649}
\newcommand{\EFk}[1]{\textcolor{EFk}{#1}} % font-lock-keyword-face
\definecolor{EFd}{HTML}{84888b}
\newcommand{\EFd}[1]{\textcolor{EFd}{\textit{#1}}} % font-lock-doc-face
\definecolor{EFt}{HTML}{986801}
\newcommand{\EFt}[1]{\textcolor{EFt}{#1}} % font-lock-type-face
\definecolor{EFs}{HTML}{50a14f}
\newcommand{\EFs}[1]{\textcolor{EFs}{#1}} % font-lock-string-face
\definecolor{EFw}{HTML}{986801}
\newcommand{\EFw}[1]{\textcolor{EFw}{#1}} % font-lock-warning-face
\definecolor{EFb}{HTML}{a626a4}
\newcommand{\EFb}[1]{\textcolor{EFb}{#1}} % font-lock-builtin-face
\definecolor{EFct}{HTML}{9ca0a4}
\newcommand{\EFct}[1]{\textcolor{EFct}{#1}} % font-lock-comment-face
\definecolor{EFc}{HTML}{b751b6}
\newcommand{\EFc}[1]{\textcolor{EFc}{#1}} % font-lock-constant-face
\definecolor{EFpp}{HTML}{4078f2}
\newcommand{\EFpp}[1]{\textcolor{EFpp}{\textbf{#1}}} % font-lock-preprocessor-face
\definecolor{EFnc}{HTML}{4078f2}
\newcommand{\EFnc}[1]{\textcolor{EFnc}{\textbf{#1}}} % font-lock-negation-char-face
\definecolor{EFv}{HTML}{6a1868}
\newcommand{\EFv}[1]{\textcolor{EFv}{#1}} % font-lock-variable-name-face
\definecolor{EFf}{HTML}{a626a4}
\newcommand{\EFf}[1]{\textcolor{EFf}{#1}} % font-lock-function-name-face
\definecolor{EFcd}{HTML}{9ca0a4}
\newcommand{\EFcd}[1]{\textcolor{EFcd}{#1}} % font-lock-comment-delimiter-face
\definecolor{EFrc}{HTML}{4078f2}
\newcommand{\EFrc}[1]{\textcolor{EFrc}{\textbf{#1}}} % font-lock-regexp-grouping-construct
\definecolor{EFrb}{HTML}{4078f2}
\newcommand{\EFrb}[1]{\textcolor{EFrb}{\textbf{#1}}} % font-lock-regexp-grouping-backslash
\definecolor{EFhn}{HTML}{da8548}
\newcommand{\EFhn}[1]{\textcolor{EFhn}{\textbf{#1}}} % highlight-numbers-number
\definecolor{EFhq}{HTML}{4078f2}
\newcommand{\EFhq}[1]{\textcolor{EFhq}{#1}} % highlight-quoted-quote
\definecolor{EFhs}{HTML}{986801}
\newcommand{\EFhs}[1]{\textcolor{EFhs}{#1}} % highlight-quoted-symbol
\definecolor{EFrdi}{HTML}{4078f2}
\newcommand{\EFrdi}[1]{\textcolor{EFrdi}{#1}} % rainbow-delimiters-depth-1-face
\definecolor{EFrdii}{HTML}{a626a4}
\newcommand{\EFrdii}[1]{\textcolor{EFrdii}{#1}} % rainbow-delimiters-depth-2-face
\definecolor{EFrdiii}{HTML}{50a14f}
\newcommand{\EFrdiii}[1]{\textcolor{EFrdiii}{#1}} % rainbow-delimiters-depth-3-face
\definecolor{EFrdiv}{HTML}{da8548}
\newcommand{\EFrdiv}[1]{\textcolor{EFrdiv}{#1}} % rainbow-delimiters-depth-4-face
\definecolor{EFrdv}{HTML}{b751b6}
\newcommand{\EFrdv}[1]{\textcolor{EFrdv}{#1}} % rainbow-delimiters-depth-5-face
\definecolor{EFrdvi}{HTML}{986801}
\newcommand{\EFrdvi}[1]{\textcolor{EFrdvi}{#1}} % rainbow-delimiters-depth-6-face
\definecolor{EFrdvii}{HTML}{4db5bd}
\newcommand{\EFrdvii}[1]{\textcolor{EFrdvii}{#1}} % rainbow-delimiters-depth-7-face
\definecolor{EFrdiix}{HTML}{80a880}
\newcommand{\EFrdiix}[1]{\textcolor{EFrdiix}{#1}} % rainbow-delimiters-depth-8-face
\definecolor{EFrdix}{HTML}{887070}
\newcommand{\EFrdix}[1]{\textcolor{EFrdix}{#1}} % rainbow-delimiters-depth-9-face
% end features
\usetheme[progressbar=foot]{metropolis}
\author{Timothy}
\date{2021-03-30}
\title{Git Good}
\subtitle{Linus Torvalds' Magical Time Machine \emoji{23f0}}

  \colorlet{greenyblue}{blue!70!green}
  \colorlet{blueygreen}{blue!40!green}
  \providecolor{link}{named}{greenyblue}
  \providecolor{cite}{named}{blueygreen}
  \hypersetup{
    pdfauthor={Timothy},
    pdftitle={Git Good},
    pdfkeywords={},
    pdfsubject={},
    pdfcreator={Emacs 28.0.50 (Org mode 9.5)},
    pdflang={English},
    breaklinks=true,
    colorlinks=true,
    linkcolor=,
    urlcolor=link,
    citecolor=cite
}
  \urlstyle{same}
  \begin{document}

\maketitle

\section{Keeping track of files is hard}
\label{sec:-keeping-track}
\begin{frame}[label={sec:weve-all-seen}]{We've all seen it before \emoji{1f62b}}
\begin{center}
\includegraphics[width=.9\linewidth]{file-mess-1.png}
\end{center}
\end{frame}
\begin{frame}[label={sec:keeping-track-files}]{We've all seen it before (2) \emoji{1f62b} \emoji{1f62b}}
\begin{center}
\includegraphics[width=.9\linewidth]{file-mess-2.png}
\end{center}
\end{frame}
\begin{frame}[label={sec:compsci-group-project}]{The CompSci Group Project issue}
\begin{itemize}
\item Your group project is due tonight and your code is ready for submission
\item While running a final test (for good luck \emoji{1f91e}) you discover a minor \alert{bug} your
group member forgot about
\item You accidentally changed working code and ended up breaking a chunk of code
you don't understand \emoji{1f631}
\item You no longer remember what was and wasn't there
\item It is 23:58 \emoji{1f630}
\end{itemize}
\end{frame}
\begin{frame}[label={sec:an-actual-physics},fragile]{An actual physics report I was working on}
 \begin{itemize}
\item I'm a last minute person, report is due tomorrow
\item It's manageable, I typed up \(\frac{2}{3}\) of it yesterday
\item I'm moving an image in the \emph{Discussion} section around, Microsoft Word freezes \emoji{2744}
\item I wait a few minutes, oh well, looks like I need to Force Quit
\item Re-open the document: Word complains that it's corrupted, and that it can't
restore the file \emoji{1f611}
\item I look at my \texttt{Report v3.docx}, it's from several hours ago
\item I need to re-do at least half of the work I've done \emoji{1f629}
\item I settle in for a later night than I was planning on\ldots{} \emoji{23f3}
\end{itemize}
\end{frame}
\section{Introduction}
\label{sec:introduction}
\begin{frame}[label={sec:version-control-systems}]{Version control systems --- recording changes to files over time}
It keeps track of changes. \\
It keeps track of changes \emph{really} well.
\begin{itemize}
\item My changes \emoji{1f642}
\item Your group member's changes \emoji{1f600}
\item The version that's been sent to the customer \emoji{1f911}
\item The version that's being tested with an urgent bugfix  \emoji{1f601}
\item The new experimental version that might break everything else \emoji{1f607}
\item Whatever other changes have happened\ldots{} \emoji{1f60d}
\end{itemize}
\end{frame}
\begin{frame}[label={sec:what-git},fragile]{What is Git?}
 \begin{itemize}
\item Open source project \emph{circa.} 2005 (developed for the Linux kernel \emoji{1f427})
\item A command line utility (but there are graphical interfaces)
\item Imagine \Verb{\color{EFD}\textcolor[HTML]{986801}{git}} as something sitting on top of your file system
\item A distributed \emoji{1f4e1} version control system --- \acr{dvcs}
\item Keeps all change info in a \texttt{.git} folder
\end{itemize}
\end{frame}
\begin{frame}[label={sec:aside-distributed-version}]{Aside: Distributed Version Control Systems (\acr{dvcs})}
A thing that solves our earlier problems
\begin{description}
\item[{\alert{Version control system}}] A system recording changes to files over time
\item[{\alert{Distributed}}] No main server, full history available to anyone
\end{description}
\end{frame}
\begin{frame}[label={sec:git-structured-way},fragile]{Git: A structured way of storing versions and changes}
 \begin{itemize}
\item Every change is stored as a new compressed file, and can easily generate the
difference with a previous version
\item This creates a structure known as a \acr{dag}\footnote{Directed Acyclic Graph}
\item \Verb{\color{EFD}\textcolor[HTML]{986801}{git}} operates on ---and provides an interface to--- this structure

\begin{center}
\includegraphics[width=.9\linewidth]{git-rebaseing.png}
\end{center}
\end{itemize}
\end{frame}
\begin{frame}[label={sec:what-does-this}]{What does this mean?}
You'll have no reason to \alert{ever} lose your work again, and \emph{unparalleled} ability to
traverse and review changes made.
\end{frame}

\section{Getting started}
\label{sec:getting-started}
\begin{frame}[label={sec:setup},fragile]{Setup}
 \begin{itemize}
\item Download \Verb{\color{EFD}\textcolor[HTML]{986801}{git}}
\item There are nice graphical interfaced, but we'll introduce those later
\item The git commands are universal, and the simplest way to get started
\end{itemize}
\end{frame}

\begin{frame}[label={sec:creating-repository-ie},fragile]{Creating a repository (i.e. project)}
 Create a new directory \emoji{1f4c1} (e.g. \texttt{my big project}), open a terminal within it and
execute
\begin{center}
\Verb{\color{EFD}\textcolor[HTML]{986801}{git} init}
\end{center}
Congratulations, you've created a repository \emoji{1f4d4}
\end{frame}

\begin{frame}[label={sec:clone-repository},fragile]{Clone a repository}
 Want to build on somebody else's work? That's easy!

\begin{center}
\Verb{\color{EFD}\textcolor[HTML]{986801}{git} clone /path/to/repository}
\end{center}

This also works with remote servers,  e.g. \Verb{\color{EFD}\textcolor[HTML]{986801}{git} clone https://github.com/tecosaur/vscode-settings.git}.
\end{frame}

\begin{frame}[label={sec:workflow},fragile]{Workflow}
 Local repo contains three trees in the .git file
\begin{itemize}
\item Working directory --- Where all the files are
\item Index --- The staging area
\item \verb~HEAD~ --- The latest commit
\end{itemize}
\end{frame}
\begin{frame}[label={sec:add-commit},fragile]{Add and commit}
 After changing some files you add it to the index tree

\begin{center}
\Verb{\color{EFD}\textcolor[HTML]{986801}{git} add \$\EFv{filename}} \\
\Verb{\color{EFD}\textcolor[HTML]{986801}{git} add *}
\end{center}

Then to actually commit them to the \verb~HEAD~
\begin{center}
\Verb{\color{EFD}\textcolor[HTML]{986801}{git} commit -m \EFs{"Message"}}
\end{center}
All commits need a message and are given an identifying serial number, which is
a hash of its structure and contents.

Your changes are still local however
\end{frame}
\begin{frame}[label={sec:whats-with-these}]{What's with these messages?}
There is no hard and fast rule but the idea is to \alert{describe} what this commit does
\begin{itemize}
\item Adds support for \emph{x}. Fixes bug that caused \emph{y}.
\item Removes changes made in commit \emph{z}.
\item Add discussion of errors to report
\end{itemize}

Looking at a list of commit messages should give a decent idea of what happened
to the code. Try to improve on the following commit messages:
\begin{itemize}
\item General commit
\item Made some changes
\item Bug-fixes
\item Debugging 4: Reloaded (continued)
\begin{itemize}
\item \emph{I've actually done this before}
\end{itemize}
\end{itemize}
\end{frame}
\begin{frame}[label={sec:so-what-are},fragile]{So, what are we doing?}
 Git tracks the changes between files
\begin{itemize}
\item Additions
\item Deletions
\end{itemize}
Starting from a \verb~HEAD~ and given a sequence of commits, you could follow what each
says and end up at the same final point
\end{frame}
\section{The next few steps}
\label{sec:-next-few}
\begin{frame}[label={sec:pushing-pulling},fragile]{Pushing and Pulling}
 To send your committed changes back to someone else's copy \emoji{1f4e1}
\begin{center}
\Verb{\color{EFD}\textcolor[HTML]{986801}{git} push origin \$\EFv{branch}}
\end{center}

And to fetch some new changes \emoji{1f6f0}
\begin{center}
\Verb{\color{EFD}\textcolor[HTML]{986801}{git} pull}
\end{center}
\end{frame}

\begin{frame}[label={sec:branching},fragile]{Branching}
 Used to develop features isolated from the main code (remember your tragic
mistake just before submitting?) either master or main is the default branch.
To create a new branch named ``feature''
\begin{center}
\Verb{\color{EFD}\textcolor[HTML]{986801}{git} checkout -b feature}
\end{center}
Switch back to master/main
\begin{center}
\Verb{\color{EFD}\textcolor[HTML]{986801}{git} checkout master/main}
\end{center}

\begin{center}
\includegraphics[width=0.7\linewidth]{git-branching.png}
\end{center}
\end{frame}
\begin{frame}[label={sec:next-few-steps},fragile]{Branching}
 A branch --- or any other change --- is \alert{not available to others unless} you \alert{push} it to your remote repository
\begin{center}
\Verb{\color{EFD}\textcolor[HTML]{986801}{git} push origin \$\EFv{branch}}
\end{center}
\end{frame}

\begin{frame}[label={sec:merging},fragile]{Merging}
 To bring down any changes made by someone or somewhere else
\begin{center}
\Verb{\color{EFD}\textcolor[HTML]{986801}{git} pull}
\end{center}
To merge another branch into your current branch (e.g. \texttt{master})
\begin{center}
\Verb{\color{EFD}\textcolor[HTML]{986801}{git} merge \$\EFv{branch}}
\end{center}
This will attempt to merge any changes from \Verb{\color{EFD}\$\EFv{branch}} into the branch your
current \verb~HEAD~ is on

\begin{center}
\includegraphics[width=.9\linewidth]{git-merging.png}
\end{center}
\end{frame}
\begin{frame}[label={sec:merge-conflicts},fragile]{Merge Conflicts}
 In both cases \texttt{git} tries to auto-merge changes. \alert{Conflicts} --- two different
changes to the same part of the same file --- need to be resolved
manually and added before trying again.
\begin{center}
\Verb{\color{EFD}\textcolor[HTML]{986801}{git} add \$\EFv{filename}}
\end{center}
One can also \alert{preview} changes (to see if conflicts will occur \emoji{1f440})
\begin{center}
\Verb{\color{EFD}\textcolor[HTML]{986801}{git} diff \$\EFv{source\_branch} \$\EFv{target\_branch}}
\end{center}

\hfill

\begin{center}
\includegraphics[width=.9\linewidth]{git-merging.png}
\end{center}
\end{frame}
\begin{frame}[label={sec:tagging},fragile]{Tagging}
 When you hit a major milestone \emoji{1f64c} (it works, we've submitted etc.) you can tag a
particular commit
\begin{center}
\Verb{\color{EFD}\textcolor[HTML]{986801}{git} tag 1.0.0 2b331ie545}
\end{center}
The \texttt{2b...} is the first 10 characters of the commit \acr{id} you want to reference.
You can find a commit \acr{id} by looking at the \alert{log}.
\end{frame}
\begin{frame}[label={sec:log},fragile]{Log}
 You can study a repository history using \Verb{\color{EFD}\textcolor[HTML]{986801}{git} log}.
There are many nice options
\begin{center}
\Verb{\color{EFD}\textcolor[HTML]{986801}{git} log --pretty=oneline}
\end{center}
Or maybe you'd like to see some \acr{ascii} art
\begin{center}
\Verb{\color{EFD}\textcolor[HTML]{986801}{git} log --graph --oneline --decorate --all}
\end{center}
See only which files have changed
\begin{center}
\Verb{\color{EFD}\textcolor[HTML]{986801}{git} log --name-status}\\
\Verb{\color{EFD}\textcolor[HTML]{986801}{git} log --help}
\end{center}
\end{frame}
\begin{frame}[label={sec:oooops}]{Oooops}
Halp, I destroyed \alert{everything}.\\
All the files are gone, I've replaced them with photos of Nicholas Cage, I'm
tired and in need of a hug.

\begin{quote}
I wish I could go back in time \emoji{23f2}
\end{quote}

% fetched from https://cdn3.iconfinder.com/data/icons/back-to-the-future/512/delorean-04-512.png
\begin{center}
\includegraphics[width=0.2\linewidth]{/tmp/cdn3-iconfinder-com-data-icons-back-to-the-future-512-delorean-04-512.png}
\end{center}
\end{frame}

\begin{frame}[label={sec:no-problem},fragile]{No problem!}
 \begin{quote}
I wish I could go back in time \emoji{23f2}
\end{quote}

You can! You can replace local changes with
\begin{center}
\Verb{\color{EFD}\textcolor[HTML]{986801}{git} checkout -- \$\EFv{filename}}
\end{center}
Or if you've committed a bunch of stuff that's wrong and just want to copy from
the main repository --- you could \Verb{\color{EFD}\textcolor[HTML]{986801}{git} clone} a new copy, or you can
\begin{center}
\Verb{\color{EFD}\textcolor[HTML]{986801}{git} fetch origin}\\
\Verb{\color{EFD}\textcolor[HTML]{986801}{git} reset --hard origin/master}
\end{center}
\end{frame}

\section{Summary}
\label{sec:-summary}
\begin{frame}[label={sec:summary}]{Summary}
\begin{itemize}
\item Git tracks changes to files
\begin{itemize}
\item Changes are stored as commits (cheap and plentiful)
\item A group of commits can be pushed (setting them in stone --- kinda)
\end{itemize}
\item Branches allow you to develop new things in isolation
\begin{itemize}
\item Can be merged back together again when finished
\item You can move through time and code together
\end{itemize}
\end{itemize}

There's a lot more you can recover from
\end{frame}
\begin{frame}[label={sec:hosted-git}]{Hosted Git}
GitHub is a popular online host --- software forge --- for Git. Plus some (a lot) of stuff

Alternatives include:
\begin{itemize}
\item \href{https://gitlab.com/}{GitLab}
\item \href{https://bitbucket.org/}{BitBucket}
\item \href{https://sourcehut.org/}{SourceHut}
\end{itemize}
These take care of backups and many, many fancy things you will likely learn in good time
\end{frame}
\end{document}
