Adds references and branches slides

Mostly adds slides about references and branches. Also tweaked python
start code and re-aranged / tweaked some existing slides
master
Jonathan Hodgson 5 years ago
parent 22ef5f581d
commit c6c938207f
  1. 11
      code-examples/python-start.py
  2. 223
      main.latex
  3. 9
      shell/branch-diff
  4. 8
      shell/cat-master-and-head
  5. 13
      shell/create-first-branch
  6. 7
      shell/delete-test-branch
  7. 21
      shell/differing-branches-simple
  8. 2
      shell/git-init
  9. 9
      shell/simple-merge

@ -1,6 +1,7 @@
import sys #!/usr/bin/env python
def main():
print("Hello")
if __name__ == "__main__": def main():
main() print("Hello")
if __name__ == "__main__":
main()

@ -69,43 +69,50 @@
} }
\begin{frame} \begin{frame}
\frametitle{Obligitary XKCD Comic} \frametitle{What is Git}
\begin{center}
\includegraphics[width=\textwidth,height=0.8\textheight,keepaspectratio]{auto-xkcd-1597.png}
\end{center}
\note{%
I have done this
Git has a reputation for being hard.
It's interface abstracts away a lot of the work, meaning it's commands can feel like magic. When it works, this is fine but unfortunately when things go wrong, you can be left - like in this comic - with no idea how to proceed. A very versatile Version Control System
I think that understanding a bit about how Git works under the hood will help de-mistily it.
Git's data model is actually quite simple. Understanding the basics of this can really help.
}
\end{frame}
\begin{frame}
\frametitle{Why bother?}
\begin{itemize} \begin{itemize}
\item Keep track of source code (or other folders and files) \item Keep track of source code (or other folders and files) and its history
\item Facilitate collaboration \item Facilitate collaboration
\item Distributed
\end{itemize} \end{itemize}
\note{% \note{%
This applies to most (if not all) version control systems. Git is still being developed.
Being distributed means you can work on repositories offline (Unlike SVN).
It's useful even if you're working on things by your self. This presentation is version controlled. It's useful even if you're working on things by your self. This presentation is version controlled.
You can use it to find out when something broke. I won't be covering it today but there is a tool called git bisect that can take a unit test (or script) to analyse when something broke using a binary search. You can use it to find out when something broke. I won't be covering it today but there is a tool called git bisect that can take a unit test (or script) to analyse when something broke using a binary search.
I think with a lot of tools that we use, having a deeper understanding of how they work means that we can use them better.
} }
\end{frame} \end{frame}
\begin{frame}
\frametitle{Obligitary XKCD Comic}
\begin{center}
\includegraphics[width=\textwidth,height=0.8\textheight,keepaspectratio]{auto-xkcd-1597.png}
\end{center}
\note{%
I have done this
Git has a reputation for being hard.
It's interface abstracts away a lot of the work, meaning it's commands can feel like magic. When it works, this is fine but unfortunately when things go wrong, you can be left - like in this comic - with no idea how to proceed.
It's interface can be confusing, there are some commands that do a lot (checkout) and there are often multiple ways to achieve something.
I think that understanding a bit about how Git works under the hood will help de-mistily it.
Git's data model is actually quite simple (beautiful even). Understanding the basics of this can really help.
}
\end{frame}
\begin{frame}[fragile] \begin{frame}[fragile]
\frametitle{Install} \frametitle{Install}
@ -121,6 +128,9 @@
# Mac # Mac
brew install git brew install git
# Get the Version
git --version
\end{minted} \end{minted}
\href{https://gitforwindows.org/}{Git for Windows: https://gitforwindows.org/} \href{https://gitforwindows.org/}{Git for Windows: https://gitforwindows.org/}
@ -131,6 +141,8 @@
There is a version of Git provided with xcode, but it is old. Most of the stuff we cover today should still work but (for example) some things need to be run from the root directory in old versions of git that don't in newer versions. There is a version of Git provided with xcode, but it is old. Most of the stuff we cover today should still work but (for example) some things need to be run from the root directory in old versions of git that don't in newer versions.
If you have the misfortune to be using windows, I've heard good things about Git for Windows but have not used it personally. It includes Bash emulation. If you have the misfortune to be using windows, I've heard good things about Git for Windows but have not used it personally. It includes Bash emulation.
Hopefully you have a version greater than 2.23.0 - if not, it's not the end of the world.
} }
\end{frame} \end{frame}
@ -272,7 +284,7 @@
\note{% \note{%
\begin{itemize} \begin{itemize}
\item This is a simple representation of the folder structure we saw, although for simplicity, I'm only showing 3 revisions. \item This is a simple representation of the folder structure we saw, although for simplicity, I'm only showing 3 revisions.
\item Notice that so the computer knows the order, somewhere in each "snapshot", we include a reference to the previous snapshot \item Notice that so the computer knows the order, somewhere in each ``snapshot", we include a reference to the previous snapshot
\end{itemize} \end{itemize}
} }
\end{frame} \end{frame}
@ -378,6 +390,8 @@
\end{center} \end{center}
\note{% \note{%
Create repo and create a file called greeting.py. Make sure to mark it as executable. Create repo and create a file called greeting.py. Make sure to mark it as executable.
Here we see the branch we are on (Master), we are told that there are no commits yet and we see that Git can see the file we've just made but it isn't tracking it.
} }
\end{frame} \end{frame}
@ -406,7 +420,7 @@
\includegraphics[width=\textwidth,height=0.8\textheight,keepaspectratio]{auto-shell-show-staging-area.pdf} \includegraphics[width=\textwidth,height=0.8\textheight,keepaspectratio]{auto-shell-show-staging-area.pdf}
\end{center} \end{center}
\note{% \note{%
Here can use git status to see what is in the staging area. They are listed in the "Changes to be committed" section. By default, they will also be green if you have colour switched on. Here can use git status to see what is in the staging area. They are listed in the ``Changes to be committed" section. By default, they will also be green if you have colour switched on.
} }
\end{frame} \end{frame}
@ -424,7 +438,7 @@
\begin{itemize} \begin{itemize}
\item Normally in contributing.md or similar \item Normally in contributing.md or similar
\end{itemize} \end{itemize}
\item Use the imperative: "Fix bug" and not "Fixed bug" or "Fixes bug." \item Use the imperative: ``Fix bug" and not ``Fixed bug" or ``Fixes bug."
\end{itemize} \end{itemize}
\note{% \note{%
First line is often shown by various tools First line is often shown by various tools
@ -566,14 +580,171 @@
\end{frame} \end{frame}
\begin{frame} \begin{frame}
\frametitle{Branch References} \frametitle{References}
\begin{center}
\includegraphics[width=\textwidth,height=0.8\textheight,keepaspectratio]{auto-shell-cat-master-and-head.pdf}
\end{center}
\begin{itemize}
\item References are stored in the \mintinline{bash}{.git/refs} folder
\item The \mintinline{bash}{heads} folder contains references to the heads (or tips) of all local branches
\end{itemize}
\note{%
}
\end{frame}
\begin{frame}
\frametitle{References}
\framesubtitle{HEAD}
\begin{itemize}
\item The HEAD references is directly in the \mintinline{bash}{.git} folder.
\item It refers to the ``current" commit. It is how git knows where you are.
\item This normally refers to a branch's head commit.
\item In some situations it will refer to a commit directly.
\end{itemize}
\note{%
Not sure why it is not in refs folder
If it refers directly to a commit, the repository is in what is called a ``detached head" state.
}
\end{frame}
\begin{frame}[fragile]
\frametitle{.gitignore}
This file tells git which files not to track.
\begin{minted}{bash}
*.log
*.doc
*.pem
*.docx
*.jpg
*.jpeg
*.pdf
*.png
.DS_Store/
*.min.css
*.min.js
dist/
\end{minted}
\note{%
This will not stop git tracking a file if it's already being tracked.
If you start tracking large binary files, git isn't going to be able to compress them. This will result in a massive repo and a headache for everyone. If at all possible, don't track large files, especially if they are going to be changed. Remember, git stores each version of each file. With text, this is fine as it can be compressed efficiently. If it's not text, it can't.
You should probably also try to avoid including minified files as git won't be able to merge them automatically.
}
\end{frame}
\begin{frame}[fragile]
\frametitle{Branches}
\begin{itemize}
\item Allows multiple features to be developed in parallel without interference.
\item Allows multiple people to collaborate easily.
\end{itemize}
\begin{minted}{bash}
# List Branches
git branch # -v adds more info
# Create a branch called test
git branch test # or
cp ~/.git/refs/heads/master ~/.git/refs/heads/test
# Switch to new branch
git switch test # or
git checkout test
# Create and switch in one go
git switch -cc test # or
git checkout -be test
\end{minted}
\note{%
Branches are represented in git as references in the heads folder.
They can be created by simply creating a file there.
The git checkout command does A LOT of stuff. It can be confusing so it's functionality has been split up into several smaller commands. If you have git 2.23.0 or newer, you will be able to use it.
Be aware that a lot of tutorials etc. will use the checkout command. Version 2.23.0 was released in August 2019.
}
\end{frame}
\begin{frame}
\frametitle{Branches}
\begin{center}
\includegraphics[width=\textwidth,height=0.8\textheight,keepaspectratio]{auto-shell-create-first-branch.pdf}
\end{center}
\note{%
As we saw, there are numerous ways to create the commit.
What is interesting to note here is that both are still currently pointing at the same commit.
Head is pointing at test so any new commits will be on this branch.
Also take note of the git log command. \mintinline{bash}{--on-line} shows a short version and \mintinline{bash}{--all} shows all branches.
}
\end{frame}
\begin{frame}
\frametitle{Differing Branches}
\begin{center}
\includegraphics[width=\textwidth,height=0.8\textheight,keepaspectratio]{auto-shell-differing-branches-simple.pdf}
\end{center}
\note{%
}
\end{frame}
\begin{frame}
\frametitle{Differing Branches}
\begin{center}
\includegraphics[width=\textwidth,height=0.8\textheight,keepaspectratio]{auto-shell-branch-diff.pdf}
\end{center}
\note{%
This shows what would be needed to take you from master to test.
Notice the \mintinline{bash}{--graph} flag which adds the drawing to the left
}
\end{frame}
\begin{frame}
\frametitle{Simple Merge}
\begin{center}
\includegraphics[width=\textwidth,height=0.8\textheight,keepaspectratio]{auto-shell-simple-merge.pdf}
\end{center}
\note{%
After working on septate branches, you will probably want to merge them eventually.
In this situation, Git was able to work everything out itself.
}
\end{frame}
\begin{frame}
\frametitle{Tidy Up}
\begin{center}
\includegraphics[width=\textwidth,height=0.8\textheight,keepaspectratio]{auto-shell-simple-merge.pdf}
\end{center}
\note{%
\note{% \note{%
} }
\end{frame} \end{frame}
\begin{frame} \begin{frame}
\frametitle{gitignore} \frametitle{Git $\ne$ GitHub}
\begin{itemize}
\item GitHub is one of many services that offer hosting for git remotes
\item It is owned by Microsoft now
\item It is not open source
\item You can't self host it
\item It it very popular
\end{itemize}
\note{%
}
\end{frame} \end{frame}
\begin{frame} \begin{frame}

@ -0,0 +1,9 @@
#!/usr/bin/env bash
cd /tmp/demo/
echo '$ git log --oneline --all --graph'
git -c color.ui=always log --oneline --all --graph --decorate=short
echo '$ git diff mater..test'
git -c color.ui=always diff master..test

@ -0,0 +1,8 @@
#!/usr/bin/env bash
cd /tmp/demo
echo '$ cat .git/refs/heads/master'
cat .git/refs/heads/master
echo '$ cat .git/HEAD'
cat .git/HEAD

@ -0,0 +1,13 @@
#!/usr/bin/env bash
cd /tmp/demo
git switch master > /dev/null
git branch -D test > /dev/null
echo '$ git branch -v'
git -c color.ui=always branch -v
echo '$ git switch -c test'
git -c color.ui=always switch -c test
echo '$ git branch -v'
git -c color.ui=always branch -v
echo '$ git log --oneline --all'
git -c color.ui=always log --oneline --all --decorate=short

@ -0,0 +1,7 @@
#!/usr/bin/env bash
cd /tmp/demo
echo '$ git switch master'
git switch master
echo '$ git branch -d test'
git branch -d test

@ -0,0 +1,21 @@
#!/usr/bin/env bash
cd /tmp/demo
echo '$ git switch master'
git switch master
echo '$ vim greeting.py'
sed -i 's/Hello World/HELLO WORLD/g' greeting.py > /dev/null
echo ' # CAPITALISE HELLO WORLD #'
echo '$ git commit -am "Capitalises Hello World"'
git -c color.ui=always commit -am "Capitalises Hello World"
echo '$ git switch test'
git switch test
echo '$ vim greeting.py'
sed -i '3iimport sys\n' greeting.py > /dev/null
echo ' # Adds the line "import sys" #'
echo '$ git commit -am "Adds sys import for arg parsing"'
git commit -am "Adds sys import for arg parsing"
#echo '$ git diff master..test'
#git -c color.ui=always diff master..test
#echo '$ git log --all --oneline --graph'
#git -c color.ui=always log --all --oneline --graph --decorate=short

@ -6,3 +6,5 @@ echo '$ cd /tmp/demo'
cd /tmp/demo/ cd /tmp/demo/
echo '$ git init' echo '$ git init'
git -c colour.ui=always init git -c colour.ui=always init
echo '$ git status'
git -c colour.ui=always status

@ -0,0 +1,9 @@
#!/usr/bin/env bash
cd /tmp/demo
echo '$ git switch master'
git switch master
echo '$ git merge test'
git merge test
echo '$ git log --oneline --all --graph'
git -c color.ui=always log --oneline --all --graph --decorate=short
Loading…
Cancel
Save