remotes.tex 8.72 KB
Newer Older
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
\documentclass[slidestop]{beamer}

\title{Git and remote repositories}
\providecommand{\myConference}{Git course}
\providecommand{\myDate}{Monday, October 14, 2013}
\author{Martijn Vermaat}
\providecommand{\myGroup}{Leiden Genome Technology Center}
\providecommand{\myDepartment}{Department of Human Genetics}
\providecommand{\myCenter}{Center for Human and Clinical Genetics}
\providecommand{\lastCenterLogo}{
  \raisebox{-0.1cm}{
    \includegraphics[height=1cm]{lgtc_logo}
    %\includegraphics[height=0.7cm]{ngi_logo}
  }
}
\providecommand{\lastRightLogo}{
  %\includegraphics[height=0.7cm]{nbic_logo}
  %\includegraphics[height=0.8cm]{nwo_logo_en}
  %\hspace{1.5cm}\includegraphics[height=0.7cm]{gen2phen_logo}
}

\usetheme{lumc}

\lstset{
  basicstyle=\ttfamily,
  language=none,
  frame=none,
  numbers=none,
  numbersep=0
}

\AtBeginSection[]
{
  \begin{frame}
    \frametitle{Table of contents}
    \tableofcontents[currentsection]
  \end{frame}
}

\begin{document}

% This disables the \pause command, handy in the editing phase.
%\renewcommand{\pause}{}

% Make the title page.
\bodytemplate


\section{Remote repositories}

\begin{frame}
  \frametitle{Distributed Git}
  Repositories can reference each other:
  \begin{itemize}
    \item A repository can be on a server, your desktop, your coworker's
      laptop, etc.
    \item Technically, no repository is `special'.
    \item We call a reference to another repository a {\em remote}.
  \end{itemize}
  \pause
  \bigskip
  \includegraphics[width=6cm]{images/repositories}
\end{frame}

\begin{frame}[fragile]
  \frametitle{Listing remotes}
  \begin{lstlisting}
$ git remote
gitlab
  \end{lstlisting}
  \bigskip
  We are on \bt{aida} and have one remote, \bt{gitlab}, defined.
  \pause
  \bigskip
  \begin{lstlisting}[basicstyle=\ttfamily\footnotesize]
$ git remote -v
gitlab  https://git.lumc.nl/m.vermaat.hg/tv-series.git (fetch)
gitlab  https://git.lumc.nl/m.vermaat.hg/tv-series.git (push)
  \end{lstlisting}
  \bigskip
  \bt{-v}: Include remote location.\\
  \vspace{1cm}
  We see that communication with \bt{gitlab} is over HTTPS.
\end{frame}

\begin{frame}[fragile]
  \frametitle{Adding a remote: \bt{git remote add}}
  \begin{lstlisting}
$ git remote add hue 192.168.0.8:projects/tv-series
  \end{lstlisting}
  \bigskip
  This adds a reference to the remote repository \bt{hue} using communication
  over SSH.
  \pause
  \bigskip
  \begin{lstlisting}[basicstyle=\ttfamily\footnotesize]
$ git remote -v
gitlab  https://git.lumc.nl/m.vermaat.hg/tv-series.git (fetch)
gitlab  https://git.lumc.nl/m.vermaat.hg/tv-series.git (push)
hue     192.168.0.8:projects/tv-series (fetch)
hue     192.168.0.8:projects/tv-series (push)
  \end{lstlisting}
\end{frame}

\begin{frame}
  \frametitle{Remote branches}
  You see code from remotes as {\em remote branches}:
  \begin{itemize}
    \item Remote branches are just branches prefixed with the remote name.
    \item Communicate with remotes to update the remote branches.
    \item You can setup a local branch to {\em track} a remote branch.
  \end{itemize}
  \pause
  \bigskip
  \includegraphics[width=10cm]{images/example}
\end{frame}

\begin{frame}[fragile]
  \frametitle{Listing remote branches: \bt{git branch}}
  \begin{lstlisting}
$ git branch -v
* master  f1ef19c State character preference
  \end{lstlisting}
  \bigskip
  This shows only our local branches.
  \pause
  \bigskip
  \begin{lstlisting}[basicstyle=\ttfamily\footnotesize]
$ git branch -v -a
* master                f1ef19c State character preference
  remotes/gitlab/master f1ef19c State character preference
  \end{lstlisting}
  \bigskip
  \bt{-a}: Include remote branches.
\end{frame}

\begin{frame}[fragile]
  \frametitle{Updating remote branches: \bt{git fetch}}
  \begin{lstlisting}
$ git fetch hue
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From 192.168.0.8:projects/tv-series
 * [new branch]      master     -> hue/master
 * [new branch]      simpsons   -> hue/simpsons
  \end{lstlisting}
  \pause
  \bigskip
  \includegraphics[width=10cm]{images/example-hue}
\end{frame}

\begin{frame}[fragile]
  \frametitle{Merging remote branches: \bt{git merge}}
  We can merge remote branches just like normal branches.
  \bigskip
  \begin{lstlisting}
$ git merge hue/simpsons
...
  \end{lstlisting}
  \pause
  \bigskip
  Alternatively, we could continue the work of a remote branch.
\end{frame}


\begin{frame}[fragile]
  \frametitle{Creating a local tracking branch: \bt{git checkout}}
  Remote branches are `read-only':
  \begin{itemize}
    \item We cannot directly continue work on a remote branch.
    \item But we can setup a local {\em tracking branch}.
  \end{itemize}
  \bigskip
  \begin{lstlisting}
$ git checkout simpsons
Branch simpsons set up to track remote branch
simpsons from hue.
Switched to a new branch 'simpsons'
  \end{lstlisting}
  \bigskip
  What happened here?
  \begin{itemize}
    \item There was no branch \bt{simpsons}.
    \item But there was a remote branch of the same name.
    \item So Git creates a new branch based on that (and switches to it).
  \end{itemize}
\end{frame}

\begin{frame}[fragile]
  \frametitle{Working on a tracking branch}
  Let's continue working on branch \bt{simpsons}.
  \begin{lstlisting}[basicstyle=\ttfamily\footnotesize]
$ emacs FACTS.md
$ git commit -am 'Edit character presence'
[simpsons 0676334] Edit character presence
 1 file changed, 1 insertion(+), 1 deletion(-)
$ git status
# On branch simpsons
# Your branch is ahead of 'hue/simpsons' by 1 commit.
#
nothing to commit (working directory clean)
  \end{lstlisting}
  \bigskip
  \includegraphics[width=9cm]{images/example-commit}
\end{frame}

\begin{frame}[fragile]
  \frametitle{Pushing changes to a remote: \bt{git push}}
  \begin{lstlisting}
$ git push hue simpsons
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 303 bytes, done.
Total 3 (delta 1), reused 0 (delta 0)
To hue.remote:projects/tv-series
   0535b7e..0676334  simpsons -> simpsons
\end{lstlisting}
  \bigskip
  Our work on branch \bt{simpsons} is now available on remote \bt{hue} too.
\end{frame}

\begin{frame}[fragile]
  \frametitle{Cloning an existing repository}
  Instead of creating repositories using \bt{git init}, you can create a local
  {\em clone} of an existing (remote) repository.
  \bigskip
  \begin{lstlisting}[basicstyle=\ttfamily\footnotesize]
$ git clone https://git.lumc.nl/m.vermaat.hg/tv-series.git
Cloning into 'tv-series'...
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 6 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (6/6), done.
  \end{lstlisting}
  \pause
  \bigskip
  A remote called \bt{origin} is added for the original repository and branch
  \bt{master} is setup to track the original \bt{master}.
  \bigskip
  \begin{lstlisting}[basicstyle=\ttfamily\footnotesize]
$ cd tv-series/
$ git remote -v
origin  https://git.lumc.nl/m.vermaat.hg/tv-series.git (fetch)
origin  https://git.lumc.nl/m.vermaat.hg/tv-series.git (push)
  \end{lstlisting}
\end{frame}

\begin{frame}[fragile]
  \frametitle{Shortcuts for tracking branches}
  If a local branch is setup to track a remote branch, there are shortcuts for
  synchronizing them.\\
  \pause
  \vspace{1cm}
  For example, say \bt{HEAD} is on \bt{simpsons} which is tracking
  \bt{origin/simpsons}.
  \bigskip
  \begin{lstlisting}
$ git push    ==>    $ git push origin simpsons
  \end{lstlisting}
  \bigskip
  \begin{lstlisting}
$ git pull    ==>    $ git fetch origin
                     $ git merge origin/simpsons
  \end{lstlisting}
\end{frame}


\section{Working with GitLab}

\begin{frame}
  \frametitle{Using a central server}
  Git can be used by a team completely decentralized.\\
  \vspace{0.5cm}
  However, often a central server is used:
  \begin{itemize}
    \item It can be easier to communicate via the server.
    \item It can be convenient to have a canonical repository.
    \item Services such as {\em GitLab} and {\em GitHub} add many features on
      top of Git.
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{GitLab}
  Our GitLab server is at \bt{https://git.lumc.nl/}\\
  \vspace{0.5cm}
  \begin{itemize}
    \item Coupled to your LUMC account.
    \item All users can create projects.
    \item Browse repositories and edit files online.
    \item Control access for other users.
    \item Track bugs/issues/tickets.
    \item Create merge requests and do code reviews.
  \end{itemize}
\end{frame}

% todo: create gitlab project, clone gitlab project

\section{Questions?}
\lastpagetemplate
\begin{frame}
  \begin{center}
    Acknowledgements:
    \bigskip
    \bigskip

    Jeroen Laros

    Zuotian Tatum

    % https://www.atlassian.com/git

  \end{center}
\end{frame}

\end{document}