remotes.tex 8.75 KB
Newer Older
1 2
\documentclass[slidestop]{beamer}

3 4
\input{../shared/shared.tex}

5
\author{Jonathan K. Vis}
6 7
\title{\courseTitle}
\providecommand{\mySubTitle}{Git and remote repositories}
8
\providecommand{\myConference}{\courseTitle}
9
\providecommand{\myGroup}{}
10
\providecommand{\myDepartment}{Department of Human Genetics}
11 12
\providecommand{\myCenter}{}
\providecommand{\date}{6-9-2017}
13

14 15 16 17 18 19 20 21 22 23 24 25 26 27
\usetheme{lumc}

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

\AtBeginSection[]
{
  \begin{frame}
    \frametitle{Table of contents}
28
    \tableofcontents[currentsection, subsectionstyle=hide/hide]
29 30 31 32 33 34 35 36 37
  \end{frame}
}

\begin{document}

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

% Make the title page.
38
\makeTitleSlide{\includegraphics[width=3.5cm]{git_logo}}
39 40

\section{Remote repositories}
41 42
\subsection{Distributed Git}
\begin{pframe}
43 44 45 46 47 48 49 50
  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}
  \bigskip
51 52 53 54
  \pause

  \includegraphics[width=5cm]{repositories}
\end{pframe}
55

56 57
\subsection{Listing remotes}
\begin{pframe}
58 59 60 61
  \begin{lstlisting}
$ git remote
gitlab
  \end{lstlisting}
62 63

  We are on \lstinline{aida} and have one remote, \lstinline{gitlab}, defined.
64
  \pause
65

66 67
  \begin{lstlisting}[basicstyle=\ttfamily\footnotesize]
$ git remote -v
68 69
gitlab  https://git.lumc.nl/zorro/tv-series.git (fetch)
gitlab  https://git.lumc.nl/zorro/tv-series.git (push)
70
  \end{lstlisting}
71 72

  \lstinline{-v}: Include remote location.
73 74
  \bigskip

75 76 77 78 79
  We see that communication with \lstinline{gitlab} is over HTTPS.
\end{pframe}

\subsection{Adding a remote: \texttt{git remote add}}
\begin{pframe}
80
  \begin{lstlisting}
81
$ git remote add hue 192.168.0.8:docs/tv-series
82
  \end{lstlisting}
83

84
  This adds a reference to the repository on the remote machine with name
85
  \lstinline{hue}.
86
  \pause
87

88 89
  \begin{lstlisting}[basicstyle=\ttfamily\footnotesize]
$ git remote -v
90 91
gitlab  https://git.lumc.nl/zorro/tv-series.git (fetch)
gitlab  https://git.lumc.nl/zorro/tv-series.git (push)
92 93
hue     192.168.0.8:docs/tv-series (fetch)
hue     192.168.0.8:docs/tv-series (push)
94
  \end{lstlisting}
95
\end{pframe}
96

97
\section{Transferring commits between repositories}
98 99
\subsection{Fetching, merging, and pushing}
\begin{pframe}
100
  There are three main commands to work with a remote:
101
  \begin{itemize}
102 103 104
    \item \lstinline{git fetch} to update our knowledge of the remote.
    \item \lstinline{git merge} to use the remote commits.
    \item \lstinline{git push} to send our local commits to the remote.
105
  \end{itemize}
106 107
  (There's a shortcut for the first two: \lstinline{git pull})
\end{pframe}
108

109 110
\subsection{Updating remote commits: \texttt{git fetch}}
\begin{pframe}
111 112 113 114 115 116
  \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.
117
From 192.168.0.8:docs/tv-series
118 119 120 121
 * [new branch]      master     -> hue/master
  \end{lstlisting}
  \pause

122 123 124 125 126
  \includegraphics[width=10cm]{example-hue}
\end{pframe}

\subsection{Merging remote information: \texttt{git merge}}
\begin{pframe}
127
  We can merge the commits from a remote into our own.
128
  \begin{lstlisting}
129 130 131 132 133
$ git merge hue/master
Updating c7f3bd9..251a51b
Fast-forward
testlib.py |    2 +
1 file changed, 2 insertions(+)
134 135 136
  \end{lstlisting}
  \pause

137 138 139 140 141
  \includegraphics[width=10cm]{example-hue-merged}
\end{pframe}

\subsection{Continue adding commits locally}
\begin{pframe}
142 143
  If we add some more commits, our local repository gets ahead of the remote
  repository.
144
  \begin{lstlisting}
145 146
$ ...
$ git commit
147
  \end{lstlisting}
148
  \pause
149

150 151 152 153 154 155
  \includegraphics[width=10cm]{example-hue-ahead}
\end{pframe}

\subsection{Pushing changes to a remote: \texttt{git push}}
\begin{pframe}
  \vspace{-0.5cm}
156
  \begin{lstlisting}
157
$ git push hue master
158 159 160 161 162
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)
163
To hue.remote:docs/tv-series
164 165
   0535b7e..0676334  simpsons -> simpsons
\end{lstlisting}
166
  \pause
167

168 169 170 171 172 173 174
  \includegraphics[width=9cm]{example-hue-pushed}
\end{pframe}

\subsection{Cloning an existing repository}
\begin{pframe}
  Instead of creating repositories using \lstinline{git init}, you can create a
  local {\em clone} of an existing (remote) repository.
175
  \begin{lstlisting}[basicstyle=\ttfamily\footnotesize]
176
$ git clone https://git.lumc.nl/zorro/tv-series.git
177 178 179 180 181 182 183
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
184 185

  A remote called \lstinline{origin} is added for the original repository
186
  automatically.
187 188 189
  \begin{lstlisting}[basicstyle=\ttfamily\footnotesize]
$ cd tv-series/
$ git remote -v
190 191
origin  https://git.lumc.nl/zorro/tv-series.git (fetch)
origin  https://git.lumc.nl/zorro/tv-series.git (push)
192
  \end{lstlisting}
193
\end{pframe}
194

195 196 197 198
\subsection{Shortcuts for pulling and pushing}
\begin{pframe}
  The full forms of \lstinline{git push/fetch/merge} get boring quickly, so
  there are some shortcuts.
199
  \bigskip
200 201 202
  \pause

  For example, if our remote is called \lstinline{origin}:
203
  \begin{lstlisting}
204
$ git push    ==>    $ git push origin master
205
  \end{lstlisting}
206

207 208
  \begin{lstlisting}
$ git pull    ==>    $ git fetch origin
209
                     $ git merge origin/master
210
  \end{lstlisting}
211 212 213 214 215 216
\end{pframe}

\subsection{Shortcuts for pulling and pushing (setup)}
\begin{pframe}
  The full forms of \lstinline{git push/fetch/merge} get boring quickly, so
  there are some shortcuts.
217
  \bigskip
218 219 220

  This needs configuration by using \lstinline{git push} with \lstinline{-u}
  once:
221 222 223
  \begin{lstlisting}
$ git push origin master -u
  \end{lstlisting}
224

225 226
  If your repository was created by cloning, this is already done.
\end{pframe}
227

228 229 230
\section{Remote protocols}
\subsection{Remote protocols}
\begin{pframe}
231 232 233 234 235 236 237
  Git can use four major protocols to transfer data:
  \begin{itemize}
    \item Local
    \item HTTP(S)
    \item SSH
    \item Git protocol
  \end{itemize}
238
\end{pframe}
239

240 241
\subsection{The local protocol}
\begin{pframe}
242 243 244 245 246
  Used when the remote repository is in another directory on the same
  machine.
  \begin{lstlisting}
$ git clone /opt/git/project.git
  \end{lstlisting}
247

248 249 250 251
  or
  \begin{lstlisting}
$ git clone file:///opt/git/project.git
  \end{lstlisting}
252
\end{pframe}
253

254 255
\subsection{The HTTP(S) protocol}
\begin{pframe}
256 257 258 259
  Most popular protocol when the remote repository is on a server.
  \begin{lstlisting}
$ git clone https://example.com/gitproject.git
  \end{lstlisting}
260

261 262
  For pushing (or fetching if the repository is private), this asks for your
  username and password everytime.
263
\end{pframe}
264

265 266
\subsection{The SSH protocol}
\begin{pframe}
267 268 269 270 271
  Most convenient protocol when the remote repository is private or you are a
  regular contributor.
  \begin{lstlisting}
$ git clone user@example.com:gitproject.git
  \end{lstlisting}
272

273
  This usually requires public/private key authentication.
274
\end{pframe}
275

276 277
\subsection{The Git protocol}
\begin{pframe}
278 279 280 281
  Originally the best performing protocol.
  \begin{lstlisting}
$ git clone git://example.com/gitproject.git
  \end{lstlisting}
282

283
  Only for fetching and often blocked by the institute firewall.
284
\end{pframe}
285 286

\section{Remotes on GitLab}
287 288 289 290
\subsection{Using a central server}
\begin{pframe}
  Git can be used by a team completely decentralized.
  \bigskip
291 292 293 294 295 296 297 298

  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}
299
\end{pframe}
300

301 302 303
\subsection{GitLab}
\begin{pframe}
  Our GitLab server is at \url{https://git.lumc.nl/}
304 305 306 307 308 309 310 311
  \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}
312
\end{pframe}
313

314 315 316 317
\subsection{GitLab clone URLs}
\begin{pframe}
  To clone a repository from GitLab, you need its clone URL.
  \bigskip
318

319 320
  \includegraphics[width=8cm]{gitlab}
  \bigskip
321

322 323
  You can choose to use the HTTPS or the SSH protocol.
\end{pframe}
324

325 326 327 328 329
\makeAcknowledgementsSlide{
  \begin{tabular}{l}
    \acknowledgements
  \end{tabular}
  \bigskip
330

331
  \hfill\includegraphics[width=3.5cm]{git_logo}
332

333 334 335 336 337
  \begin{tabular}{l}
    \small\url{http://git-scm.com/book}\\
    \small\url{https://www.atlassian.com/git}
  \end{tabular}
}
338

339
\end{document}