diff --git a/tips/tips.tex b/tips/tips.tex index e10ee0bd427ccb87741917eee004c9f6137d3cee..a19a0701cb79a0c83a07399d750568c2579a9f20 100644 --- a/tips/tips.tex +++ b/tips/tips.tex @@ -2,7 +2,7 @@ \title{Git Tips and Tricks} \providecommand{\myConference}{Git course} -\providecommand{\myDate}{Monday, July 7, 2014} +\providecommand{\myDate}{Monday, June 23, 2014} \author{Wibowo Arindrarto} \providecommand{\myGroup}{Sequencing Analysis Support Core} \providecommand{\myDepartment}{} @@ -43,6 +43,269 @@ \end{frame} +\section{Custom Prompt} +\begin{frame}[fragile] + \frametitle{} + + Checking which branch you are working on and its status is + a routine task. + \bigskip + \pause + + ``\bt{git status}'' is useful, but quickly feels repetitive. + \begin{lstlisting}[language=none, caption=Routine git checking] + $ git branch + * master + $ git status + nothing to commit, working directory clean + \end{lstlisting} + \bigskip + \pause + + Solution: use a custom shell prompt that displays git status. + \begin{lstlisting}[language=none, caption=Git checking with custom prompt] + (master) $ git st + nothing to commit, working directory clean + \end{lstlisting} + \bigskip + +\end{frame} + + +\section{Custom Prompt} +\begin{frame}[fragile] + \frametitle{} + + The git-approved way to do this is to use the ``\bt{\_\_git\_ps1}'' + shell function defined in the ``\bt{git-prompt.sh}'' file. + \bigskip + \pause + + The location of this file depends on your OS and git version. For now, + you can download a copy of this file from our GitLab. + \bigskip + \pause + + Then, in you ``\bt{.bashrc}'' file, add ``\bt{\_\_git\_ps1}'' to the + ``\bt{PS1}'' variable, and source your ``\bt{.bashrc}'' again. + \bigskip +\end{frame} + + +\section{Useful git commands} +\begin{frame}[fragile] + \frametitle{git blame} + + Git tracks each line of each file in its repository. + \bigskip + \pause + + You can view who committed the line change, the commit hash, + and the commit time using ``\bt{git blame}'' + \begin{lstlisting}[language=none, caption=git blame command] + $ git blame README + a4394d28 (bow 2014-06 ...) Second version. + \end{lstlisting} + \bigskip +\end{frame} + + +\section{Useful git commands} +\begin{frame}[fragile] + \frametitle{git tag} + + Sometimes, it is practical to refer to a commit with a name + instead of a hash. + \bigskip + \pause + + Official releases, for example, are better referred as v1.0 + than a76a0fx. + \bigskip + \pause + + This can be done using ``\bt{git tag}''. +\end{frame} + + +\section{Useful git commands} +\begin{frame}[fragile] + \frametitle{git tag} + + \begin{lstlisting}[language=none, caption=Adding a tag] + $ git tag "v0.0.1" + $ git show v0.0.1 + commit a4394d28e6ba30be19318ee74f732a103b8ffdf2 + Author: bow <bow@bow.web.id> + Date: Sat Jun 21 13:47:03 2014 +0200 + + Second commit + + diff --git a/README b/README + index efe6f7c..4fe6328 100644 + --- a/README + +++ b/README + @@ -1 +1 @@ + -First version. + +Second version. + \end{lstlisting} + \bigskip +\end{frame} + + +\section{Useful git commands} +\begin{frame}[fragile] + \frametitle{git tag} + + What we did previously is to add what is called a lightweight tag. + Lightweight tags are essentially commit aliases. + \bigskip + \pause + + There is another type of tag, called the annotated tag. + \bigskip + \pause + + Annotated tags contain more information: tagger identity, + tagging message, tagging date, and can be verified with GPG. + \bigskip +\end{frame} + + +\section{Useful git commands} +\begin{frame}[fragile] + \frametitle{git tag} + \begin{lstlisting}[language=none, caption=Adding an annotated tag] + $ git tag -a "v0.0.1" -m "Alpha version" + tag v0.1.0 + Tagger: bow <bow@bow.web.id> + Date: Sat Jun 21 15:11:53 2014 +0200 + + Alpha version + + commit a4394d28e6ba30be19318ee74f732a103b8ffdf2 + Author: bow <bow@bow.web.id> + Date: Sat Jun 21 13:47:03 2014 +0200 + + Second commit + + diff --git a/README b/README + index efe6f7c..4fe6328 100644 + --- a/README + +++ b/README + @@ -1 +1 @@ + -First version. + +Second version. + \end{lstlisting} + \bigskip +\end{frame} + + +\section{Useful git options} +\begin{frame}[fragile] + \frametitle{git diff -w} + + Sometimes, you want to hide whitespace differences when using + ``\bt{git diff}''. + \bigskip + \pause + + This can be done via ``\bt{git diff -w}'' + \begin{lstlisting}[language=none, caption=git diff without whitespace] + $ git diff -w + \end{lstlisting} + \bigskip + \pause + + Note that while this aids visualization of the diff, git will still + commit the whitespace change. + \bigskip +\end{frame} + + +\section{Useful git options} +\begin{frame}[fragile] + \frametitle{git commit --amend} + + Git gives you total control over your history, which means you can also + change them. + \bigskip + \pause + + This practice is potentially dangerous and should not be part of your + regular workflow. This is especially true for public commits. + \bigskip + \pause + + Still, there are times when changing that one last commit makes more + sense than doing a ``\bt{git revert}'' + \bigskip + \pause + + ``\bt{git commit --amend}'' allows you to do that: changing your last + commit. + \bigskip +\end{frame} + + +\section{Useful git options} +\begin{frame}[fragile] + \frametitle{git commit --amend} + + When run on a clean branch (no uncommitted changes), + ``\bt{git commit --amend}'' allows you to change your last commit message. + \bigskip + \pause + + You can also use the command to meld current staged changes to your last + committed change. + \begin{lstlisting}[language=none, caption=git blame command] + $ git status + Changes to be committed: + modified: README + $ git commit --amend -m "Update README" + [master b60437d] Second update + 1 file changed, 1 insertion(+), 1 deletion(-) + \end{lstlisting} + \bigskip +\end{frame} + + +\section{Useful git options} +\begin{frame}[fragile] + \frametitle{git add --patch} + + Often, uncommited change overextends. You start with the intention of + fixing bug A, but in the middle found that you can implement feature B + and feature C while also squashing bug D. + \bigskip + \pause + + At the end of the day, only ``\bt{git commit -am "Updates"}'' is done + and the whole change is saved in a single comit. + \bigskip + \pause + + This defeats the purpose of tracking your changes in commits. Commits + ideally represents a single, functional update, which you can understand + later on. + \bigskip +\end{frame} + + +\section{Useful git options} +\begin{frame}[fragile] + \frametitle{git add --patch} + + You can, infact, commit the line changes selectively. This helps + split a mesh of changes into separate commits. + \begin{lstlisting}[language=none, caption=git add --patch] + $ git add --patch + \end{lstlisting} + \bigskip +\end{frame} + + \section{Main Configuration File} \begin{frame}[fragile] \frametitle{Viewing} @@ -75,13 +338,14 @@ \bigskip \pause - You can also use the ``\bt{git config}'' to set the values via the shell. + You can also use the ``\bt{git config --global}'' to set the values via the shell. \begin{lstlisting}[language=none, caption=Modifying via the shell] - $ git config user.name "Linus Torvalds" + $ git config --global user.name "Linus Torvalds" \end{lstlisting} \bigskip \end{frame} + \section{Main Configuration File} \begin{frame}[fragile] \frametitle{Modifying: global ignore} @@ -114,7 +378,8 @@ \begin{lstlisting}[language=none, caption=Setting the global ignore file] $ echo "*.out" > ~/.gitignore_global $ echo "testing.txt" > ~/.gitignore_global - $ git config core.excludesfile "~/.gitignore_global" + $ git config --global core.excludesfile \ + "~/.gitignore_global" \end{lstlisting} \bigskip \pause @@ -129,6 +394,37 @@ \end{frame} +\section{Main Configuration File} +\begin{frame}[fragile] + \frametitle{Aliases} + + You can alias simple commands. + \begin{lstlisting}[language=none, caption=Simple alias] + $ git config --global alias.st status + $ git st + nothing to commit, working directory clean + \end{lstlisting} + \bigskip + \pause + + Or more complex commands. + \begin{lstlisting}[language=none, caption=Complex alias] + $ git config --global alias.qlog \ + "log --pretty=oneline" + $ git qlog + a4394d28e... Second commit + 80eafd7e6... First commit + \end{lstlisting} + \bigskip +\end{frame} + + +\section{GitLab and GitHub} +\begin{frame}[fragile] + \frametitle{Demo time!} +\end{frame} + + \section{Questions?} \lastpagetemplate \begin{fframe} @@ -141,8 +437,6 @@ Jeroen F. J. Laros - Zuotian Tatum - \end{center} \vfill