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

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

Mihai's avatar
Mihai committed
5
\author{}
6 7
\title{\courseTitle}
\providecommand{\mySubTitle}{Git and remote repositories}
8
\providecommand{\myConference}{\courseTitle}
9
\providecommand{\myGroup}{}
Mihai's avatar
Mihai committed
10
\providecommand{\myDepartment}{}
11
\providecommand{\myCenter}{}
12

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

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

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

\begin{document}

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

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

\section{Remote repositories}
40 41
\subsection{Distributed Git}
\begin{pframe}
42 43 44 45 46
  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'.
Mihai's avatar
Mihai committed
47
    \item We call a reference to another repository a \cmdarg{remote}.
48 49
  \end{itemize}
  \bigskip
Mihai's avatar
Mihai committed
50
\end{pframe}
51

Mihai's avatar
Mihai committed
52 53 54 55
\begin{pframe}
 \begin{center}
   \includegraphics[width=\textwidth]{images/remotes_00.pdf}
 \end{center}
56
\end{pframe}
57

58 59
\subsection{Listing remotes}
\begin{pframe}
Mihai's avatar
Mihai committed
60 61
  \begin{framed}
\prompt\ \gitcmd\ \cmd{remote} \\
Mihai's avatar
Mihai committed
62
\cmdarg{gitlab}
Mihai's avatar
Mihai committed
63
  \end{framed}
64

Mihai's avatar
Mihai committed
65 66
  We are on \cmdarg{aida} and have one remote, \cmdarg{gitlab}, defined.
\end{pframe}
67

Mihai's avatar
Mihai committed
68 69 70 71 72 73 74
\begin{pframe}
 \begin{center}
   \includegraphics[width=\textwidth]{images/remotes_01.pdf}
 \end{center}
\end{pframe}

\begin{pframe}
Mihai's avatar
Mihai committed
75 76 77
  \begin{framed}
\prompt\ \gitcmd\ \cmd{remote} \cmdopt{-v}\\
\small{
Mihai's avatar
Mihai committed
78 79
\cmdarg{gitlab} \cliout{https://git.lumc.nl/zorro/tv-series.git (fetch)}\\
\cmdarg{gitlab} \cliout{https://git.lumc.nl/zorro/tv-series.git (push)}}
Mihai's avatar
Mihai committed
80
  \end{framed}
81

Mihai's avatar
Mihai committed
82
  \cmdopt{-v}: Include remote location.
83

Mihai's avatar
Mihai committed
84
  We see that communication with \cmdarg{gitlab} is over HTTPS.
85 86 87 88
\end{pframe}

\subsection{Adding a remote: \texttt{git remote add}}
\begin{pframe}
Mihai's avatar
Mihai committed
89 90 91
  \begin{framed}
\prompt\ \gitcmd\ \cmd{remote} \cmd{add} \cmdarg{hue} \cmdarg{192.168.0.8:docs/tv-series}
  \end{framed}
92

93
  This adds a reference to the repository on the remote machine with name
Mihai's avatar
Mihai committed
94
  \cmdarg{hue}.
95
  \pause
96

Mihai's avatar
Mihai committed
97 98 99
  \begin{framed}
\prompt\ \gitcmd\ \cmd{remote} \cmdopt{-v}\\
\small{
Mihai's avatar
Mihai committed
100 101 102 103
\cmdarg{gitlab} \cliout{https://git.lumc.nl/zorro/tv-series.git (fetch)}\\
\cmdarg{gitlab} \cliout{https://git.lumc.nl/zorro/tv-series.git (push)}\\
\cmdarg{hue} \cliout{192.168.0.8:docs/tv-series (fetch)}\\
\cmdarg{hue} \cliout{192.168.0.8:docs/tv-series (push)}}
Mihai's avatar
Mihai committed
104
  \end{framed}
105
\end{pframe}
106

Mihai's avatar
Mihai committed
107 108 109 110 111 112
\begin{pframe}
 \begin{center}
   \includegraphics[width=\textwidth]{images/remotes_02.pdf}
 \end{center}
\end{pframe}

113
\section{Transferring commits between repositories}
114 115
\subsection{Fetching, merging, and pushing}
\begin{pframe}
116
  There are three main commands to work with a remote:
117
  \begin{itemize}
Mihai's avatar
Mihai committed
118 119 120
    \item \gitcmd\ \cmd{fetch} to update our knowledge of the remote.
    \item \gitcmd\ \cmd{merge} to use the remote commits.
    \item \gitcmd\ \cmd{push} to send our local commits to the remote.
121
  \end{itemize}
Mihai's avatar
Mihai committed
122
  (There's a shortcut for the first two: \gitcmd\ \cmd{pull})
123
\end{pframe}
124

Mihai's avatar
Mihai committed
125 126 127 128 129 130
\begin{pframe}
 \begin{center}
   \includegraphics[width=\textwidth]{images/commit_graph_00.pdf}
 \end{center}
\end{pframe}

131 132
\subsection{Updating remote commits: \texttt{git fetch}}
\begin{pframe}
133 134
  \begin{framed}
\prompt\  \gitcmd\ \cmd{fetch} \cmdarg{hue}\\
Mihai's avatar
Mihai committed
135
\small{
136 137 138 139 140
\cliout{remote: Counting objects: 5, done.}
\cliout{remote: Compressing objects: 100\% (2/2), done.}\\
\cliout{remote: Total 3 (delta 0), reused 0 (delta 0)}\\
\cliout{Unpacking objects: 100\% (3/3), done.}\\
\cliout{From 192.168.0.8:docs/tv-series}\\
Mihai's avatar
Mihai committed
141
\cliout{ * [new branch]      master     -> hue/master}}
142
  \end{framed}
143 144
  \pause

Mihai's avatar
Mihai committed
145 146 147 148
  \vspace{-0.5cm}
 \begin{center}
   \includegraphics[width=\textwidth]{images/commit_graph_01.pdf}
 \end{center}
149 150 151 152
\end{pframe}

\subsection{Merging remote information: \texttt{git merge}}
\begin{pframe}
Mihai's avatar
Mihai committed
153 154
  We can \cmd{merge} the commits from a remote into our own \cmdarg{master}.
  \vspace{-0.4cm}
155 156
  \begin{framed}
\prompt\  \gitcmd\ \cmd{merge} \cmdarg{hue/master}\\
Mihai's avatar
Mihai committed
157
\small{
158 159 160
\cliout{Updating c7f3bd9..251a51b}\\
\cliout{Fast-forward}\\
\cliout{testlib.py |    2 +}\\
Mihai's avatar
Mihai committed
161
\cliout{1 file changed, 2 insertions(+)}}
162
  \end{framed}
163 164
  \pause

Mihai's avatar
Mihai committed
165 166 167 168
  \vspace{-0.6cm}
  \begin{center}
   \includegraphics[width=\textwidth]{images/commit_graph_02.pdf}
  \end{center}
169 170 171 172
\end{pframe}

\subsection{Continue adding commits locally}
\begin{pframe}
173 174
  If we add some more commits, our local repository gets ahead of the remote
  repository.
Mihai's avatar
Mihai committed
175
  \vspace{-0.3cm}
176 177 178 179
  \begin{framed}
\prompt\ ... \\
\prompt\  \gitcmd\ \cmd{commit}
  \end{framed}
180
  \pause
181

Mihai's avatar
Mihai committed
182 183 184 185 186
 \vspace{-0.5cm}
 \begin{center}
   \includegraphics[width=\textwidth]{images/commit_graph_03.pdf}
 \end{center}
%   \includegraphics[width=10cm]{example-hue-ahead}
187 188 189 190 191
\end{pframe}

\subsection{Pushing changes to a remote: \texttt{git push}}
\begin{pframe}
  \vspace{-0.5cm}
192 193
  \begin{framed}
\prompt\  \gitcmd\ \cmd{push} \cmdarg{hue} \cmdarg{master}\\
Mihai's avatar
Mihai committed
194
\small{
195 196 197 198 199 200
\cliout{Counting objects: 5, done.}\\
\cliout{Delta compression using up to 4 threads.}\\
\cliout{Compressing objects: 100\% (2/2), done.}\\
\cliout{Writing objects: 100\% (3/3), 303 bytes, done.}\\
\cliout{Total 3 (delta 1), reused 0 (delta 0)}\\
\cliout{To hue.remote:docs/tv-series}\\
Mihai's avatar
Mihai committed
201
\cliout{0535b7e..0676334  simpsons -> simpsons}}
202
  \end{framed}
Mihai's avatar
Mihai committed
203
\end{pframe}
204

Mihai's avatar
Mihai committed
205 206 207 208 209
\begin{pframe}
  \vspace{0.8cm}
  \begin{center}
   \includegraphics[width=\textwidth]{images/commit_graph_04.pdf}
  \end{center}
210 211 212 213
\end{pframe}

\subsection{Cloning an existing repository}
\begin{pframe}
214
  Instead of creating repositories using \gitcmd\ \cmd{init}, you can create a
Mihai's avatar
Mihai committed
215
  local \cmd{clone} of an existing (remote) repository.
216 217
  \begin{framed}
\prompt\  \gitcmd\ \cmd{clone} \cmdarg{https://git.lumc.nl/zorro/tv-series.git}\\
Mihai's avatar
Mihai committed
218
\small{
219 220 221 222
\cliout{Cloning into 'tv-series'...}\\
\cliout{remote: Counting objects: 6, done.}\\
\cliout{remote: Compressing objects: 100\% (4/4), done.}\\
\cliout{remote: Total 6 (delta 1), reused 0 (delta 0)}\\
Mihai's avatar
Mihai committed
223
\cliout{Unpacking objects: 100\% (6/6), done.}}
224 225
  \end{framed}
\end{pframe}
226

227 228
\begin{pframe}
  A remote called \cmdarg{origin} is added for the original repository
229
  automatically.
230 231 232 233
  \begin{framed}
\prompt\ \cmd{cd} \cmdarg{tv-series/}\\
\prompt\ \gitcmd\ \cmd{remote} \cmdopt{-v}\\
\small{
Mihai's avatar
Mihai committed
234 235
\cmdarg{origin} \cliout{https://git.lumc.nl/zorro/tv-series.git (fetch)}\\
\cmdarg{origin} \cliout{https://git.lumc.nl/zorro/tv-series.git (push)}}
236
  \end{framed}
237
\end{pframe}
238

239 240
\subsection{Shortcuts for pulling and pushing}
\begin{pframe}
241
  The full forms of \gitcmd\ \cmd{push}/\cmd{fetch}/\cmd{merge} get boring quickly, so
242
  there are some shortcuts.
243
  \bigskip
244 245
  \pause

246 247 248 249
  For example, if our remote is called \cmdarg{origin}:
  \vspace{-0.3cm}
  \begin{framed}
\prompt\ \gitcmd\ \cmd{push}\\
Mihai's avatar
Mihai committed
250
- instead of -\\
251 252 253
\prompt\ \gitcmd\ \cmd{push} \cmdarg{origin} \cmdarg{master}
  \end{framed}
  \vspace{-0.6cm}
254

255 256
  \begin{framed}
\prompt\ \gitcmd\ \cmd{pull}\\
Mihai's avatar
Mihai committed
257
- instead of -\\
258 259 260
\prompt\ \gitcmd\ \cmd{fetch} \cmdarg{origin}\\
\prompt\ \gitcmd\ \cmd{merge} \cmdarg{origin/master}
  \end{framed}
261 262 263 264 265 266
\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.
267
  \bigskip
268

269
  This needs configuration by using \gitcmd\ \cmd{push} with \cmdopt{-u}
270
  once:
271 272 273
  \begin{framed}
\prompt\ \gitcmd\ \cmd{push} \cmdarg{origin} \cmdarg{master} \cmdopt{-u}
  \end{framed}
274

275 276
  If your repository was created by cloning, this is already done.
\end{pframe}
277

278 279 280
\section{Remote protocols}
\subsection{Remote protocols}
\begin{pframe}
281
  Git can use two major protocols to transfer data:
282 283 284 285
  \begin{itemize}
    \item HTTP(S)
    \item SSH
  \end{itemize}
286
\end{pframe}
287

288 289
\subsection{The HTTP(S) protocol}
\begin{pframe}
290
  Most popular protocol when the remote repository is on a server.
291 292 293
  \begin{framed}
\prompt\ \gitcmd\ \cmd{clone} \cmdarg{https://example.com/gitproject.git}
  \end{framed}
294

295 296
  For pushing (or fetching if the repository is private), this asks for your
  username and password everytime.
297
\end{pframe}
298

299 300
\subsection{The SSH protocol}
\begin{pframe}
301 302
  Most convenient protocol when the remote repository is private or you are a
  regular contributor.
303 304 305
  \begin{framed}
\prompt\ \gitcmd\ \cmd{clone} \cmdarg{user@example.com:gitproject.git}
  \end{framed}
306

307
  This usually requires public/private key authentication.
308
\end{pframe}
309 310

\section{Remotes on GitLab}
311 312 313 314
\subsection{Using a central server}
\begin{pframe}
  Git can be used by a team completely decentralized.
  \bigskip
315 316 317 318 319 320 321 322

  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}
323
\end{pframe}
324

325 326 327
\subsection{GitLab}
\begin{pframe}
  Our GitLab server is at \url{https://git.lumc.nl/}
328 329 330 331 332 333 334 335
  \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}
336
\end{pframe}
337

338 339 340 341
\subsection{GitLab clone URLs}
\begin{pframe}
  To clone a repository from GitLab, you need its clone URL.
  \bigskip
342

343 344
  \includegraphics[width=8cm]{gitlab}
  \bigskip
345

346 347
  You can choose to use the HTTPS or the SSH protocol.
\end{pframe}
348

349 350 351 352
\subsection{GitLab Projects}
\begin{pframe}
 Every project belongs to a single namespace, either a:
 \begin{itemize}
Mihai's avatar
Mihai committed
353
  \item User:
354 355 356
  \begin{itemize}
   \item The project owner has direct control over the project.
  \end{itemize}
Mihai's avatar
Mihai committed
357
  \item Group:
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
  \begin{itemize}
   \item The group's user-level permissions will take effect.
  \end{itemize}
 \end{itemize}
 \medskip
 Every project has a visibility level:
 \begin{itemize}
  \item A way of controling who has \textbf{read} access to that project.
  \item Note that this controls both git ``fetch'' access as well as access to the web UI for that project.
 \end{itemize}
\end{pframe}

\subsection{Project visibility levels}
\begin{pframe}
  \begin{itemize}
    \item Private projects:
    \begin{itemize}
      \item The project owner must explicitly grant access to specific users.
      \item Are not listed on the public access directory.
    \end{itemize}
  \end{itemize}
Mihai's avatar
Mihai committed
379

380 381 382 383 384 385 386 387
  \begin{itemize}
    \item Internal projects:
    \begin{itemize}
      \item Can be cloned by any logged in user.
      \item Are listed on the public access directory for logged in users.
      \item Logged in users have Guest permissions on the repository.
    \end{itemize}
  \end{itemize}
Mihai's avatar
Mihai committed
388

389 390 391 392 393 394 395 396 397 398
  \begin{itemize}
    \item Public projects:
    \begin{itemize}
      \item Can be cloned without any authentication.
      \item Are listed on the public access directory.
      \item Logged in users have Guest permissions on the repository.
    \end{itemize}
  \end{itemize}
\end{pframe}

399 400 401 402 403
\makeAcknowledgementsSlide{
  \begin{tabular}{l}
    \acknowledgements
  \end{tabular}
  \bigskip
404

405
  \hfill\includegraphics[width=3.5cm]{git_logo}
406

407 408 409 410 411
  \begin{tabular}{l}
    \small\url{http://git-scm.com/book}\\
    \small\url{https://www.atlassian.com/git}
  \end{tabular}
}
412

413
\end{document}