remotes.tex 10.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 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
50 51 52 53
  \pause

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

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

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

Mihai's avatar
Mihai 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}
71

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

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's avatar
Mihai committed
79 80 81
  \begin{framed}
\prompt\ \gitcmd\ \cmd{remote} \cmd{add} \cmdarg{hue} \cmdarg{192.168.0.8:docs/tv-series}
  \end{framed}
82

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

Mihai's avatar
Mihai 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}
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}
Mihai's avatar
Mihai 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.
105
  \end{itemize}
Mihai's avatar
Mihai committed
106
  (There's a shortcut for the first two: \gitcmd\ \cmd{pull})
107
\end{pframe}
108

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}
120 121
  \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 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}
135 136
  \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 145 146 147
  \begin{framed}
\prompt\ ... \\
\prompt\  \gitcmd\ \cmd{commit}
  \end{framed}
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 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}
166
  \pause
167

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
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}
184

185 186
\begin{pframe}
  A remote called \cmdarg{origin} is added for the original repository
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}
195
\end{pframe}
196

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
200
  there are some shortcuts.
201
  \bigskip
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}
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}
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.
225
  \bigskip
226

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

233 234
  If your repository was created by cloning, this is already done.
\end{pframe}
235

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

246 247
\subsection{The HTTP(S) protocol}
\begin{pframe}
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}
252

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

257 258
\subsection{The SSH protocol}
\begin{pframe}
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}
264

265
  This usually requires public/private key authentication.
266
\end{pframe}
267 268

\section{Remotes on GitLab}
269 270 271 272
\subsection{Using a central server}
\begin{pframe}
  Git can be used by a team completely decentralized.
  \bigskip
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}
281
\end{pframe}
282

283 284 285
\subsection{GitLab}
\begin{pframe}
  Our GitLab server is at \url{https://git.lumc.nl/}
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}
294
\end{pframe}
295

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

301 302
  \includegraphics[width=8cm]{gitlab}
  \bigskip
303

304 305
  You can choose to use the HTTPS or the SSH protocol.
\end{pframe}
306

307 308 309 310
\subsection{GitLab Projects}
\begin{pframe}
 Every project belongs to a single namespace, either a:
 \begin{itemize}
Mihai's avatar
Mihai committed
311
  \item User:
312 313 314
  \begin{itemize}
   \item The project owner has direct control over the project.
  \end{itemize}
Mihai's avatar
Mihai 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's avatar
Mihai 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's avatar
Mihai 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}

357 358 359 360 361
\makeAcknowledgementsSlide{
  \begin{tabular}{l}
    \acknowledgements
  \end{tabular}
  \bigskip
362

363
  \hfill\includegraphics[width=3.5cm]{git_logo}
364

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

371
\end{document}