remotes.tex 9.66 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
\providecommand{\myCenter}{}
12
\providecommand{\date}{22-11-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
  Git can use two major protocols to transfer data:
232 233 234 235
  \begin{itemize}
    \item HTTP(S)
    \item SSH
  \end{itemize}
236
\end{pframe}
237

238 239
\subsection{The HTTP(S) protocol}
\begin{pframe}
240 241 242 243
  Most popular protocol when the remote repository is on a server.
  \begin{lstlisting}
$ git clone https://example.com/gitproject.git
  \end{lstlisting}
244

245 246
  For pushing (or fetching if the repository is private), this asks for your
  username and password everytime.
247
\end{pframe}
248

249 250
\subsection{The SSH protocol}
\begin{pframe}
251 252 253 254 255
  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}
256

257
  This usually requires public/private key authentication.
258
\end{pframe}
259 260

\section{Remotes on GitLab}
261 262 263 264
\subsection{Using a central server}
\begin{pframe}
  Git can be used by a team completely decentralized.
  \bigskip
265 266 267 268 269 270 271 272

  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}
273
\end{pframe}
274

275 276 277
\subsection{GitLab}
\begin{pframe}
  Our GitLab server is at \url{https://git.lumc.nl/}
278 279 280 281 282 283 284 285
  \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}
286
\end{pframe}
287

288 289 290 291
\subsection{GitLab clone URLs}
\begin{pframe}
  To clone a repository from GitLab, you need its clone URL.
  \bigskip
292

293 294
  \includegraphics[width=8cm]{gitlab}
  \bigskip
295

296 297
  You can choose to use the HTTPS or the SSH protocol.
\end{pframe}
298

299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
\subsection{GitLab Projects}
\begin{pframe}
 Every project belongs to a single namespace, either a:
 \begin{itemize}
  \item User: 
  \begin{itemize}
   \item The project owner has direct control over the project.
  \end{itemize}
  \item Group: 
  \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}
  
  \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}
  
  \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}

349 350 351 352 353
\makeAcknowledgementsSlide{
  \begin{tabular}{l}
    \acknowledgements
  \end{tabular}
  \bigskip
354

355
  \hfill\includegraphics[width=3.5cm]{git_logo}
356

357 358 359 360 361
  \begin{tabular}{l}
    \small\url{http://git-scm.com/book}\\
    \small\url{https://www.atlassian.com/git}
  \end{tabular}
}
362

363
\end{document}