remotes.tex 10.2 KB
Newer Older
Vermaat's avatar
Vermaat committed
1 2
\documentclass[slidestop]{beamer}

Laros's avatar
Laros committed
3 4
\input{../shared/shared.tex}

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

Vermaat's avatar
Vermaat committed
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}
Laros's avatar
Laros committed
27
    \tableofcontents[currentsection, subsectionstyle=hide/hide]
Vermaat's avatar
Vermaat committed
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.
Laros's avatar
Laros committed
37
\makeTitleSlide{\includegraphics[width=3.5cm]{git_logo}}
Vermaat's avatar
Vermaat committed
38 39

\section{Remote repositories}
Laros's avatar
Laros committed
40 41
\subsection{Distributed Git}
\begin{pframe}
Vermaat's avatar
Vermaat committed
42 43 44 45 46 47 48 49
  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
Laros's avatar
Laros committed
50 51 52 53
  \pause

  \includegraphics[width=5cm]{repositories}
\end{pframe}
Vermaat's avatar
Vermaat committed
54

Laros's avatar
Laros committed
55 56
\subsection{Listing remotes}
\begin{pframe}
Mihai Lefter's avatar
Mihai Lefter committed
57 58 59 60
  \begin{framed}
\prompt\ \gitcmd\ \cmd{remote} \\
\cliout{gitlab}
  \end{framed}
Laros's avatar
Laros committed
61 62

  We are on \lstinline{aida} and have one remote, \lstinline{gitlab}, defined.
Vermaat's avatar
Vermaat committed
63
  \pause
Laros's avatar
Laros committed
64

Mihai Lefter's avatar
Mihai Lefter committed
65 66 67 68 69 70
  \begin{framed}
\prompt\ \gitcmd\ \cmd{remote} \cmdopt{-v}\\
\small{
\cliout{gitlab  https://git.lumc.nl/zorro/tv-series.git (fetch)}\\
\cliout{gitlab  https://git.lumc.nl/zorro/tv-series.git (push)}}
  \end{framed}
Laros's avatar
Laros committed
71

Mihai Lefter's avatar
Mihai Lefter committed
72
  \cmdopt{-v}: Include remote location.
Vermaat's avatar
Vermaat committed
73

Laros's avatar
Laros committed
74 75 76 77 78
  We see that communication with \lstinline{gitlab} is over HTTPS.
\end{pframe}

\subsection{Adding a remote: \texttt{git remote add}}
\begin{pframe}
Mihai Lefter's avatar
Mihai Lefter committed
79 80 81
  \begin{framed}
\prompt\ \gitcmd\ \cmd{remote} \cmd{add} \cmdarg{hue} \cmdarg{192.168.0.8:docs/tv-series}
  \end{framed}
Laros's avatar
Laros committed
82

Vermaat's avatar
Vermaat committed
83
  This adds a reference to the repository on the remote machine with name
Mihai Lefter's avatar
Mihai Lefter committed
84
  \cmdarg{hue}.
Vermaat's avatar
Vermaat committed
85
  \pause
Laros's avatar
Laros committed
86

Mihai Lefter's avatar
Mihai Lefter committed
87 88 89 90 91 92 93 94
  \begin{framed}
\prompt\ \gitcmd\ \cmd{remote} \cmdopt{-v}\\
\small{
\cliout{gitlab  https://git.lumc.nl/zorro/tv-series.git (fetch)}\\
\cliout{gitlab  https://git.lumc.nl/zorro/tv-series.git (push)}\\
\cliout{hue     192.168.0.8:docs/tv-series (fetch)}\\
\cliout{hue     192.168.0.8:docs/tv-series (push)}}
  \end{framed}
Laros's avatar
Laros committed
95
\end{pframe}
Vermaat's avatar
Vermaat committed
96

Vermaat's avatar
Vermaat committed
97
\section{Transferring commits between repositories}
Laros's avatar
Laros committed
98 99
\subsection{Fetching, merging, and pushing}
\begin{pframe}
Vermaat's avatar
Vermaat committed
100
  There are three main commands to work with a remote:
Vermaat's avatar
Vermaat committed
101
  \begin{itemize}
Mihai Lefter's avatar
Mihai Lefter committed
102 103 104
    \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.
Vermaat's avatar
Vermaat committed
105
  \end{itemize}
Mihai Lefter's avatar
Mihai Lefter committed
106
  (There's a shortcut for the first two: \gitcmd\ \cmd{pull})
Laros's avatar
Laros committed
107
\end{pframe}
Vermaat's avatar
Vermaat committed
108

Laros's avatar
Laros committed
109 110
\subsection{Updating remote commits: \texttt{git fetch}}
\begin{pframe}
111 112 113 114 115 116 117 118 119
  \begin{framed}
\prompt\  \gitcmd\ \cmd{fetch} \cmdarg{hue}\\
\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}\\
\cliout{ * [new branch]      master     -> hue/master}\\
  \end{framed}
Vermaat's avatar
Vermaat committed
120 121
  \pause

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

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

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

\subsection{Continue adding commits locally}
\begin{pframe}
Vermaat's avatar
Vermaat committed
142 143
  If we add some more commits, our local repository gets ahead of the remote
  repository.
144 145 146 147
  \begin{framed}
\prompt\ ... \\
\prompt\  \gitcmd\ \cmd{commit}
  \end{framed}
Vermaat's avatar
Vermaat committed
148
  \pause
Vermaat's avatar
Vermaat committed
149

Laros's avatar
Laros committed
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 157 158 159 160 161 162 163 164 165
  \begin{framed}
\prompt\  \gitcmd\ \cmd{push} \cmdarg{hue} \cmdarg{master}\\
\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}\\
\cliout{0535b7e..0676334  simpsons -> simpsons}
  \end{framed}
Vermaat's avatar
Vermaat committed
166
  \pause
Vermaat's avatar
Vermaat committed
167

Laros's avatar
Laros committed
168 169 170 171 172
  \includegraphics[width=9cm]{example-hue-pushed}
\end{pframe}

\subsection{Cloning an existing repository}
\begin{pframe}
173
  Instead of creating repositories using \gitcmd\ \cmd{init}, you can create a
Laros's avatar
Laros committed
174
  local {\em clone} of an existing (remote) repository.
175 176 177 178 179 180 181 182 183
  \begin{framed}
\prompt\  \gitcmd\ \cmd{clone} \cmdarg{https://git.lumc.nl/zorro/tv-series.git}\\
\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)}\\
\cliout{Unpacking objects: 100\% (6/6), done.}
  \end{framed}
\end{pframe}
Laros's avatar
Laros committed
184

185 186
\begin{pframe}
  A remote called \cmdarg{origin} is added for the original repository
Vermaat's avatar
Vermaat committed
187
  automatically.
188 189 190 191 192 193 194
  \begin{framed}
\prompt\ \cmd{cd} \cmdarg{tv-series/}\\
\prompt\ \gitcmd\ \cmd{remote} \cmdopt{-v}\\
\small{
\cliout{origin  https://git.lumc.nl/zorro/tv-series.git (fetch)}\\
\cliout{origin  https://git.lumc.nl/zorro/tv-series.git (push)}}
  \end{framed}
Laros's avatar
Laros committed
195
\end{pframe}
Vermaat's avatar
Vermaat committed
196

Laros's avatar
Laros committed
197 198
\subsection{Shortcuts for pulling and pushing}
\begin{pframe}
199
  The full forms of \gitcmd\ \cmd{push}/\cmd{fetch}/\cmd{merge} get boring quickly, so
Laros's avatar
Laros committed
200
  there are some shortcuts.
Vermaat's avatar
Vermaat committed
201
  \bigskip
Laros's avatar
Laros committed
202 203
  \pause

204 205 206 207 208 209 210 211
  For example, if our remote is called \cmdarg{origin}:
  \vspace{-0.3cm}
  \begin{framed}
\prompt\ \gitcmd\ \cmd{push}\\
--------\\
\prompt\ \gitcmd\ \cmd{push} \cmdarg{origin} \cmdarg{master}
  \end{framed}
  \vspace{-0.6cm}
Laros's avatar
Laros committed
212

213 214 215 216 217 218
  \begin{framed}
\prompt\ \gitcmd\ \cmd{pull}\\
--------\\
\prompt\ \gitcmd\ \cmd{fetch} \cmdarg{origin}\\
\prompt\ \gitcmd\ \cmd{merge} \cmdarg{origin/master}
  \end{framed}
Laros's avatar
Laros committed
219 220 221 222 223 224
\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.
Vermaat's avatar
Vermaat committed
225
  \bigskip
Laros's avatar
Laros committed
226

227
  This needs configuration by using \gitcmd\ \cmd{push} with \cmdopt{-u}
Laros's avatar
Laros committed
228
  once:
229 230 231
  \begin{framed}
\prompt\ \gitcmd\ \cmd{push} \cmdarg{origin} \cmdarg{master} \cmdopt{-u}
  \end{framed}
Vermaat's avatar
Vermaat committed
232

Laros's avatar
Laros committed
233 234
  If your repository was created by cloning, this is already done.
\end{pframe}
Vermaat's avatar
Vermaat committed
235

Laros's avatar
Laros committed
236 237 238
\section{Remote protocols}
\subsection{Remote protocols}
\begin{pframe}
239
  Git can use two major protocols to transfer data:
Vermaat's avatar
Vermaat committed
240 241 242 243
  \begin{itemize}
    \item HTTP(S)
    \item SSH
  \end{itemize}
Laros's avatar
Laros committed
244
\end{pframe}
Vermaat's avatar
Vermaat committed
245

Laros's avatar
Laros committed
246 247
\subsection{The HTTP(S) protocol}
\begin{pframe}
Vermaat's avatar
Vermaat committed
248
  Most popular protocol when the remote repository is on a server.
249 250 251
  \begin{framed}
\prompt\ \gitcmd\ \cmd{clone} \cmdarg{https://example.com/gitproject.git}
  \end{framed}
Laros's avatar
Laros committed
252

Vermaat's avatar
Vermaat committed
253 254
  For pushing (or fetching if the repository is private), this asks for your
  username and password everytime.
Laros's avatar
Laros committed
255
\end{pframe}
Vermaat's avatar
Vermaat committed
256

Laros's avatar
Laros committed
257 258
\subsection{The SSH protocol}
\begin{pframe}
Vermaat's avatar
Vermaat committed
259 260
  Most convenient protocol when the remote repository is private or you are a
  regular contributor.
261 262 263
  \begin{framed}
\prompt\ \gitcmd\ \cmd{clone} \cmdarg{user@example.com:gitproject.git}
  \end{framed}
Laros's avatar
Laros committed
264

Vermaat's avatar
Vermaat committed
265
  This usually requires public/private key authentication.
Laros's avatar
Laros committed
266
\end{pframe}
Vermaat's avatar
Vermaat committed
267 268

\section{Remotes on GitLab}
Laros's avatar
Laros committed
269 270 271 272
\subsection{Using a central server}
\begin{pframe}
  Git can be used by a team completely decentralized.
  \bigskip
Vermaat's avatar
Vermaat committed
273 274 275 276 277 278 279 280

  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}
Laros's avatar
Laros committed
281
\end{pframe}
Vermaat's avatar
Vermaat committed
282

Laros's avatar
Laros committed
283 284 285
\subsection{GitLab}
\begin{pframe}
  Our GitLab server is at \url{https://git.lumc.nl/}
Vermaat's avatar
Vermaat committed
286 287 288 289 290 291 292 293
  \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}
Laros's avatar
Laros committed
294
\end{pframe}
Vermaat's avatar
Vermaat committed
295

Laros's avatar
Laros committed
296 297 298 299
\subsection{GitLab clone URLs}
\begin{pframe}
  To clone a repository from GitLab, you need its clone URL.
  \bigskip
Vermaat's avatar
Vermaat committed
300

Laros's avatar
Laros committed
301 302
  \includegraphics[width=8cm]{gitlab}
  \bigskip
Vermaat's avatar
Vermaat committed
303

Laros's avatar
Laros committed
304 305
  You can choose to use the HTTPS or the SSH protocol.
\end{pframe}
Vermaat's avatar
Vermaat committed
306

307 308 309 310
\subsection{GitLab Projects}
\begin{pframe}
 Every project belongs to a single namespace, either a:
 \begin{itemize}
Mihai Lefter's avatar
Mihai Lefter committed
311
  \item User:
312 313 314
  \begin{itemize}
   \item The project owner has direct control over the project.
  \end{itemize}
Mihai Lefter's avatar
Mihai Lefter committed
315
  \item Group:
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
  \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 Lefter's avatar
Mihai Lefter committed
337

338 339 340 341 342 343 344 345
  \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 Lefter's avatar
Mihai Lefter committed
346

347 348 349 350 351 352 353 354 355 356
  \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}

Laros's avatar
Laros committed
357 358 359 360 361
\makeAcknowledgementsSlide{
  \begin{tabular}{l}
    \acknowledgements
  \end{tabular}
  \bigskip
Vermaat's avatar
Vermaat committed
362

Laros's avatar
Laros committed
363
  \hfill\includegraphics[width=3.5cm]{git_logo}
Vermaat's avatar
Vermaat committed
364

Laros's avatar
Laros committed
365 366 367 368 369
  \begin{tabular}{l}
    \small\url{http://git-scm.com/book}\\
    \small\url{https://www.atlassian.com/git}
  \end{tabular}
}
Vermaat's avatar
Vermaat committed
370

Laros's avatar
Laros committed
371
\end{document}