All content done
[ai-gitflashtalk.git] / git.tex
diff --git a/git.tex b/git.tex
index 2ffc3bd..5319eb1 100644 (file)
--- a/git.tex
+++ b/git.tex
@@ -78,7 +78,7 @@
        \end{block}
                
        \begin{block}{{\Large\Frowny\Smiley} Mac}
-               Install via XCode tools. Just run \lstinline{\$ git} and
+               Install via XCode tools. Just run \lstinline{$\$$ git} and
                when GIT is not installed it will prompt you with instructions.
        \end{block}
                        
 
 \end{frame}
 
-\section{Getting started \& Workflow}
+\section{Getting started \& workflow}
 \begin{frame}[fragile]
        \frametitle{Getting started}
        \begin{block}{Check GIT version in (GIT) bash}
                \begin{lstlisting}
-frobnicator@frobmachine:~\$ git --version
+frobnicator@frobmachine:~$\$$ git --version
 git version 1.7.10.4
                \end{lstlisting}
        \end{block}
 
        \begin{block}{Create a repository}
                \begin{lstlisting}
-frobnicator@frobmachine:~/projects\$ git init myfirstproject
+frobnicator@frobmachine:~/projects$\$$ git init myfirstproject
 Initialized empty Git repository in /home/frobnicator/projects/myfirstproject/.git/
 
-frobnicator@frobmachine:~/projects\$ ls -1 myfirstproject/.git
+frobnicator@frobmachine:~/projects$\$$ ls -1 myfirstproject/.git
 branches/
 config
 description
@@ -116,7 +116,6 @@ refs/
        \end{block}
 \end{frame}
 
-\subsection{Four (five) stages}
 \begin{frame}
        \frametitle{Four (five) stages}
        \begin{itemize}
@@ -141,9 +140,9 @@ refs/
 \begin{frame}[fragile]
        \frametitle{Add and commit}
        \begin{lstlisting}
-frobnicator@frobmachine :~/projects/myfirstproject\$ echo "This is a frobfile" > frobbedfile
+frobnicator@frobmachine:~/projects/myfirstproject$\$$ echo "This is a frobfile" > frobbedfile
 
-frobnicator@frobmachine:~/projects/myfirstproject\$ git status
+frobnicator@frobmachine:~/projects/myfirstproject$\$$ git status
 On branch master
 
 Initial commit
@@ -159,9 +158,9 @@ nothing added to commit but untracked files present (use "git add" to track)
 
 \begin{frame}[fragile]
        \begin{lstlisting}
-frobnicator@frobmachine:~/projects/myfirstproject\$ git add frobbedfile
+frobnicator@frobmachine:~/projects/myfirstproject$\$$ git add frobbedfile
 
-frobnicator@frobmachine:~/projects/myfirstproject\$ git status
+frobnicator@frobmachine:~/projects/myfirstproject$\$$ git status
 On branch master
 
 Initial commit
@@ -171,44 +170,294 @@ Changes to be committed:
 
        new file:   frobbedfile
 
-frobnicator@frobmachine:~/projects/myfirstproject\$ git commit
+frobnicator@frobmachine:~/projects/myfirstproject$\$$ git commit
 [master (root-commit) 2b7355e] Adds frobbedfile
  1 file changed, 1 insertion(+)
   create mode 100644 frobbedfile
        \end{lstlisting}
 \end{frame}
 
-\begin{frame}
+\begin{frame}[fragile]
        \frametitle{Log \& Checkout}
-       \begin{block}{\texttt{\$ git log}}
+       \begin{lstlisting}
+frobnicator@frobmachine:~/projects/myfirstproject$\$$ echo "This is a second frobbedfile" > frob2
+frobnicator@frobmachine:~/projects/myfirstproject$\$$ git add frob2
+frobnicator@frobmachine:~/projects/myfirstproject$\$$ git commit -m "This is a second commit"
+[master cd094bc] This is a second commit
+ 1 file changed, 1 insertion(+)
+ create mode 100644 frob2
+       \end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+       \frametitle{Log \& Checkout 2}
+       \begin{lstlisting}
+frobnicator@frobmachine:~/projects/myfirstproject$\$$ git log
+commit cd094bc6b81812256533395454db22da07d1e5a4
+Author: Frob Nicator <frob@nicator.net>
+Date:   Thu Apr 16 22:44:42 2015 +0200
+
+    This is a second commit
+
+commit c9c9b358cddcbee541ec433a2dc2d5ffe3e928c2
+Author: Frob Nicator <frob@nicator>
+Date:   Thu Apr 16 22:44:42 2015 +0200
+
+    Adds frobbedfile
+frobnicator@frobmachine:~/projects/myfirstproject$\$$ ls
+frob2  frobbedfile
+       \end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+       \frametitle{Log \& Checkout 2}
+       \begin{lstlisting}
+frobnicator@frobmachine:~/projects/myfirstproject$\$$ git checkout c9c9b3
+Note: checking out 'c9c9b3'.
+
+You are in 'detached HEAD' state. You can look around, make experimental
+changes and commit them, and you can discard any commits you make in this
+state without impacting any branches by performing another checkout.
+
+If you want to create a new branch to retain commits you create, you may
+do so (now or later) by using -b with the checkout command again. Example:
+
+  git checkout -b new_branch_name
+
+HEAD is now at c9c9b35... Adds frobbedfile
+frobnicator@frobmachine:~/projects/myfirstproject$\$$ ls
+frobbedfile
+       \end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+       \frametitle{Log \& Checkout 3}
+       \framesubtitle{We lost our commit and our file!}
+       \begin{lstlisting}
+frobnicator@frobmachine:~/projects/myfirstproject$\$$ git log
+commit c9c9b358cddcbee541ec433a2dc2d5ffe3e928c2
+Author: Frob Nicator <frob@nicator>
+Date:   Thu Apr 16 22:44:42 2015 +0200
+
+    Adds frobbedfile
+frobnicator@frobmachine:~/projects/myfirstproject$\$$ ls
+frobbedfile
+       \end{lstlisting}
+\end{frame}
 
+\begin{frame}[fragile]
+       \frametitle{Log \& Checkout 4}
+       \begin{block}{Ofcourse not, you never lose stuff with git}
+               \begin{lstlisting}
+frobnicator@frobmachine:~/projects/myfirstproject$\$$ git log --all
+commit cd094bc6b81812256533395454db22da07d1e5a4
+Author: Frob Nicator <frob@nicator.net>
+Date:   Thu Apr 16 22:44:42 2015 +0200
+
+    This is a second commit
+...
+...
+               \end{lstlisting}
        \end{block}
-       \begin{block}{\texttt{\$ git checkout}}
+\end{frame}
 
+\begin{frame}[fragile]
+       \frametitle{Log \& Checkout 5}
+       \begin{block}{We can just checkout the hash again}
+               \begin{lstlisting}
+frobnicator@frobmachine:~/projects/myfirstproject$\$$ ls
+frob2  frobbedfile
+frobnicator@frobmachine:~/projects/myfirstproject$\$$ git log --decorate --oneline --graph --all
+* cd094bc (HEAD, master) This is a second commit
+* c9c9b35 Adds frobbedfile
+               \end{lstlisting}
        \end{block}
 \end{frame}
 
+
 \section{Branching and unevitable merging}
 \begin{frame}
        \frametitle{Branching}
+       \begin{itemize}
+               \item Commit: State of the folder. Has and knows his parent.\\
+               \item Branch: Just a named commit.\\
+                       Usually a sidetrack of a project.\\
+                       Master, develop, feature, etc\ldots
+               \item Tag: Just a named commit.\\
+                       Usually marked point to jump to later on.\\
+                       eg. Version release, big change etc\ldots
+       \end{itemize}
 \end{frame}
 
-\begin{frame}
+\begin{frame}[fragile]
+       \frametitle{Branching 2}
+       \begin{block}{See current branch}
+               \begin{lstlisting}
+frobnicator@frobmachine:~/projects/myfirstproject$\$$ git branch
+* master
+               \end{lstlisting}
+       \end{block}
+       \begin{block}{Create new branch}
+               \begin{lstlisting}
+frobnicator@frobmachine:~/projects/myfirstproject$\$$ git checkout -b "develop"
+Switched to a new branch 'develop'
+frobnicator@frobmachine:~/projects/myfirstproject$\$$ git branch
+* develop
+  master
+               \end{lstlisting}
+       \end{block}
+       \begin{block}{Delete branch}
+               \begin{lstlisting}
+frobnicator@frobmachine:~/projects/myfirstproject$\$$ git branch -d "develop"
+Deleted branch develop (was cd094bc).
+frobnicator@frobmachine:~/projects/myfirstproject$\$$ git branch
+* master
+               \end{lstlisting}
+       \end{block}
+\end{frame}
+
+\begin{frame}[fragile]
        \frametitle{Push \& Pull}
+       \begin{block}{What?}
+               \begin{itemize}
+                       \item Push your changes upsteam repository (eg.\ github)
+                       \item Pull their changes from upstream
+                       \item Merge into your branch
+               \end{itemize}
+       \end{block}
+       \begin{block}{How?}
+               \begin{lstlisting}
+frobnicator@frobmachine:~/projects/myfirstproject$\$$ git remote add origin https://github.com/dopefishh/prj.git
+frobnicator@frobmachine:~/projects/myfirstproject$\$$ git push origin master
+frobnicator@frobmachine:~/projects/myfirstproject$\$$ git pull origin master
+               \end{lstlisting}
+       \end{block}
 \end{frame}
 
-\begin{frame}
+\begin{frame}[fragile]
        \frametitle{Merge}
+       \begin{block}{Merge develop to master}
+               \begin{lstlisting}
+frobnicator@frobmachine:~/projects/myfirstproject$\$$ git merge develop
+               \end{lstlisting}
+       \end{block}
+
+       \begin{block}{How to get a conflict}
+               \begin{itemize}
+                       \item We make a file with three lines
+                       \item On every line we set: \texttt{regelN} where N is line
+                       number.
+                       \item Change line 2 in the master and develop branch to a
+                               separate thing.
+                       \item Commit both and checkout master
+                       \item Do merge
+               \end{itemize}
+       \end{block}
+\end{frame}
+
+\begin{frame}[fragile]
+       \frametitle{Merge 2}
+       \begin{block}{Merge message}
+               \begin{lstlisting}
+frobnicator@frobmachine~/projects/myfirstproject$\$$ git merge develop
+Auto-merging mergeconfict
+CONFLICT (content): Merge conflict in mergeconfict
+Automatic merge failed; fix conflicts and then commit the result.
+               \end{lstlisting}
+       \end{block}
+       \begin{block}{Contents of mergeconflict file}
+               \begin{lstlisting}
+1 regel1                                                                          
+2 <<<<<<< HEAD                                                                    
+3 masterregel2                                                                    
+4 =======                                                                         
+5 developregel2                                                                   
+6 >>>>>>> develop                                                                 
+7 regel3  
+               \end{lstlisting}
+       \end{block}
+\end{frame}
+
+\begin{frame}[fragile]
+       \frametitle{Merge 3}
+       \begin{block}{Commit message}
+               \begin{lstlisting}
+ 1 Merge branch 'develop'                                                          
+ 2                                                                                 
+ 3 Conflicts:                                                                      
+ 4         mergeconfict                                                            
+ 5 #                                                                               
+ 6 # It looks like you may be committing a merge.                                  
+ 7 # If this is not correct, please remove the file                                
+ 8 #       .git/MERGE_HEAD                                                         
+ 9 # and try again.                                                                
+10                                                                                 
+11                                                                                 
+12 # Please enter the commit message for your changes. Lines starting              
+13 # with '#' will be ignored, and an empty message aborts the commit.             
+14 # On branch master                                                              
+15 # All conflicts fixed but you are still merging.                                
+16 #                                                                               
+17 # Changes to be committed:                                                      
+18 #       modified:   mergeconfict                                                
+19 #                                
+               \end{lstlisting}
+       \end{block}
+\end{frame}
+
+\begin{frame}[fragile]
+       \frametitle{Merge 4}
+       \begin{block}{Output from git log}
+               \begin{lstlisting}
+*   a6474c9 (HEAD, master) Merge branch 'develop'
+|\  
+| * 8b292ad (develop) Develop merge conflict
+* | 7d5018a Master merge confict
+|/  
+* 885a341 First merge conflict push
+* cd094bc This is a second commit
+* c9c9b35 Adds frobbedfile
+               \end{lstlisting}
+       \end{block}
 \end{frame}
 
 \section{Tips \& Tricks}
-\begin{frame}
+\begin{frame}[fragile]
        \frametitle{\texttt{/home/frobnicator/.gitconfig}}
+       \begin{lstlisting}
+frobnicator@frobmachine~$\$$ cat .gitconfig
+[user]
+name = Frob Nicator
+email = frob@nicator.com
+
+[alias]
+tree = log --decorate --oneline --graph --all
+pushm = push origin master
+pushd = push origin develop
+       \end{lstlisting}
 \end{frame}
 
-\begin{frame}
+\begin{frame}[fragile]
        \frametitle{Public key}
-
+       \begin{block}{SSH config}
+               \begin{lstlisting}
+frobnicator@frobmachine:~$\$$ cat .ssh/config
+Host github.com
+       IdentityFile /home/frobnicator/.ssh/github
+       User git
+               \end{lstlisting}
+       \end{block}
+       \begin{block}{Create Key}
+               \begin{lstlisting}
+frobnicator@frobmachine:~ $\$$ ssh-keygen -f /home/frobnicator/.ssh/github
+               \end{lstlisting}
+       \end{block}
+       \begin{block}{Clone with ssh}
+               \begin{lstlisting}
+frobnicator@frobmachine:~/projects/myfirstproject$\$$ git remote add origin git@github.com:frobnicator/prj.git
+frobnicator@frobmachine:~/projects/$\$$ git clone git@github.com:frobnicator/prj.git
+               \end{lstlisting}
+       \end{block}
 \end{frame}
 
 \end{document}