Skip to content
Snippets Groups Projects
Commit 6b2439ab authored by Vermaat's avatar Vermaat
Browse files

Remotes lecture without branches

parent 1eec2f3f
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
remotes/images/example-hue-ahead.png

27 KiB

This diff is collapsed.
remotes/images/example-hue-merged.png

21.2 KiB

This diff is collapsed.
remotes/images/example-hue-pushed.png

27.1 KiB

This diff is collapsed.
remotes/images/example-hue.png

41.6 KiB | W: | H:

remotes/images/example-hue.png

21 KiB | W: | H:

remotes/images/example-hue.png
remotes/images/example-hue.png
remotes/images/example-hue.png
remotes/images/example-hue.png
  • 2-up
  • Swipe
  • Onion skin
This diff is collapsed.
remotes/images/gitlab.png

16.9 KiB

......@@ -2,7 +2,7 @@
\title{Git and remote repositories}
\providecommand{\myConference}{Git course}
\providecommand{\myDate}{Monday, June 23, 2014}
\providecommand{\myDate}{Tuesday, November 30, 2015}
\author{Martijn Vermaat}
\providecommand{\myGroup}{Leiden Genome Technology Center}
\providecommand{\myDepartment}{Department of Human Genetics}
......@@ -86,65 +86,45 @@ gitlab https://git.lumc.nl/m.vermaat.hg/tv-series.git (push)
\begin{frame}[fragile]
\frametitle{Adding a remote: \bt{git remote add}}
\begin{lstlisting}
$ git remote add hue 192.168.0.8:projects/tv-series
$ git remote add hue 192.168.0.8:docs/tv-series
\end{lstlisting}
\bigskip
This adds a reference to the remote repository \bt{hue} using communication
over SSH.
This adds a reference to the repository on the remote machine with name
\bt{hue}.
\pause
\bigskip
\begin{lstlisting}[basicstyle=\ttfamily\footnotesize]
$ git remote -v
gitlab https://git.lumc.nl/m.vermaat.hg/tv-series.git (fetch)
gitlab https://git.lumc.nl/m.vermaat.hg/tv-series.git (push)
hue 192.168.0.8:projects/tv-series (fetch)
hue 192.168.0.8:projects/tv-series (push)
hue 192.168.0.8:docs/tv-series (fetch)
hue 192.168.0.8:docs/tv-series (push)
\end{lstlisting}
\end{frame}
\section{Transferring commits between repositories}
\begin{frame}
\frametitle{Remote branches}
You see code from remotes as {\em remote branches}:
\frametitle{Fetching, merging, and pushing}
There are three main commands to work with a remote:
\begin{itemize}
\item Remote branches are just branches prefixed with the remote name.
\item Communicate with remotes to update the remote branches.
\item You can setup a local branch to {\em track} a remote branch.
\item \bt{git fetch} to update our knowledge of the remote.
\item \bt{git merge} to use the remote commits.
\item \bt{git push} to send our local commits to the remote.
\end{itemize}
\pause
\bigskip
\includegraphics[width=10cm]{images/example}
\end{frame}
\begin{frame}[fragile]
\frametitle{Listing remote branches: \bt{git branch}}
\begin{lstlisting}
$ git branch -v
* master f1ef19c State character preference
\end{lstlisting}
\bigskip
This shows only our local branches.
\pause
\bigskip
\begin{lstlisting}[basicstyle=\ttfamily\footnotesize]
$ git branch -v -a
* master f1ef19c State character preference
remotes/gitlab/master f1ef19c State character preference
\end{lstlisting}
\bigskip
\bt{-a}: Include remote branches.
(There's a shortcut for the first two: \bt{git pull})
\end{frame}
\begin{frame}[fragile]
\frametitle{Updating remote branches: \bt{git fetch}}
\frametitle{Updating remote commits: \bt{git fetch}}
\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.
From 192.168.0.8:projects/tv-series
From 192.168.0.8:docs/tv-series
* [new branch] master -> hue/master
* [new branch] simpsons -> hue/simpsons
\end{lstlisting}
\pause
\bigskip
......@@ -152,75 +132,50 @@ From 192.168.0.8:projects/tv-series
\end{frame}
\begin{frame}[fragile]
\frametitle{Merging remote branches: \bt{git merge}}
We can merge remote branches just like normal branches.
\frametitle{Merging remote information: \bt{git merge}}
We can merge the commits from a remote into our own.
\bigskip
\begin{lstlisting}
$ git merge hue/simpsons
...
$ git merge hue/master
Updating c7f3bd9..251a51b
Fast-forward
testlib.py | 2 +
1 file changed, 2 insertions(+)
\end{lstlisting}
\pause
\bigskip
Alternatively, we could continue the work of a remote branch.
\includegraphics[width=10cm]{images/example-hue-merged}
\end{frame}
\begin{frame}[fragile]
\frametitle{Creating a local tracking branch: \bt{git checkout}}
Remote branches are `read-only':
\begin{itemize}
\item We cannot directly continue work on a remote branch.
\item But we can setup a local {\em tracking branch}.
\end{itemize}
\frametitle{Continue adding commits locally}
If we add some more commits, our local repository gets ahead of the remote
repository.
\bigskip
\begin{lstlisting}
$ git checkout simpsons
Branch simpsons set up to track remote branch
simpsons from hue.
Switched to a new branch 'simpsons'
\end{lstlisting}
\bigskip
What happened here?
\begin{itemize}
\item There was no branch \bt{simpsons}.
\item But there was a remote branch of the same name.
\item So Git creates a new branch based on that (and switches to it).
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Working on a tracking branch}
Let's continue working on branch \bt{simpsons}.
\begin{lstlisting}[basicstyle=\ttfamily\footnotesize]
$ emacs FACTS.md
$ git add FACTS.md
$ git commit -m 'Edit character presence'
[simpsons 0676334] Edit character presence
1 file changed, 1 insertion(+), 1 deletion(-)
$ git status
# On branch simpsons
# Your branch is ahead of 'hue/simpsons' by 1 commit.
#
nothing to commit (working directory clean)
$ ...
$ git commit
\end{lstlisting}
\pause
\bigskip
\includegraphics[width=8cm]{images/example-commit}
\includegraphics[width=10cm]{images/example-hue-ahead}
\end{frame}
\begin{frame}[fragile]
\frametitle{Pushing changes to a remote: \bt{git push}}
\begin{lstlisting}
$ git push hue simpsons
$ git push hue master
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)
To hue.remote:projects/tv-series
To hue.remote:docs/tv-series
0535b7e..0676334 simpsons -> simpsons
\end{lstlisting}
\pause
\bigskip
Our work on branch \bt{simpsons} is now available on remote \bt{hue} too.
\includegraphics[width=9cm]{images/example-hue-pushed}
\end{frame}
\begin{frame}[fragile]
......@@ -238,8 +193,8 @@ Unpacking objects: 100% (6/6), done.
\end{lstlisting}
\pause
\bigskip
A remote called \bt{origin} is added for the original repository and branch
\bt{master} is setup to track the original \bt{master}.
A remote called \bt{origin} is added for the original repository
automatically.
\bigskip
\begin{lstlisting}[basicstyle=\ttfamily\footnotesize]
$ cd tv-series/
......@@ -250,26 +205,93 @@ origin https://git.lumc.nl/m.vermaat.hg/tv-series.git (push)
\end{frame}
\begin{frame}[fragile]
\frametitle{Shortcuts for tracking branches}
If a local branch is setup to track a remote branch, there are shortcuts for
synchronizing them.\\
\frametitle{Shortcuts for pulling and pushing}
The full forms of \bt{git push/fetch/merge} get boring quickly, so there are
some shortcuts.\\
\pause
\vspace{1cm}
For example, say \bt{HEAD} is on \bt{simpsons} which is tracking
\bt{origin/simpsons}.
For example, if our remote is called \bt{origin}:
\bigskip
\begin{lstlisting}
$ git push ==> $ git push origin simpsons
$ git push ==> $ git push origin master
\end{lstlisting}
\bigskip
\begin{lstlisting}
$ git pull ==> $ git fetch origin
$ git merge origin/simpsons
$ git merge origin/master
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Shortcuts for pulling and pushing (setup)}
The full forms of \bt{git push/fetch/merge} get boring quickly, so there are
some shortcuts.\\
\vspace{1cm}
This needs configuration by using \bt{git push} with \bt{-u} once:
\bigskip
\begin{lstlisting}
$ git push origin master -u
\end{lstlisting}
\bigskip
If your repository was created by cloning, this is already done.
\end{frame}
\section{Working with GitLab}
\section{Remote protocols}
\begin{frame}[fragile]
\frametitle{Remote protocols}
Git can use four major protocols to transfer data:
\begin{itemize}
\item Local
\item HTTP(S)
\item SSH
\item Git protocol
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{The local protocol}
Used when the remote repository is in another directory on the same
machine.
\begin{lstlisting}
$ git clone /opt/git/project.git
\end{lstlisting}
or
\begin{lstlisting}
$ git clone file:///opt/git/project.git
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{The HTTP(S) protocol}
Most popular protocol when the remote repository is on a server.
\begin{lstlisting}
$ git clone https://example.com/gitproject.git
\end{lstlisting}
For pushing (or fetching if the repository is private), this asks for your
username and password everytime.
\end{frame}
\begin{frame}[fragile]
\frametitle{The SSH protocol}
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}
This usually requires public/private key authentication.
\end{frame}
\begin{frame}[fragile]
\frametitle{The Git protocol}
Originally the best performing protocol.
\begin{lstlisting}
$ git clone git://example.com/gitproject.git
\end{lstlisting}
Only for fetching and often blocked by the institute firewall.
\end{frame}
\section{Remotes on GitLab}
\begin{frame}
\frametitle{Using a central server}
......@@ -298,6 +320,15 @@ $ git pull ==> $ git fetch origin
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{GitLab clone URLs}
To clone a repository from GitLab, you need its clone URL.\\
\vspace{0.5cm}
\includegraphics[width=8cm]{images/gitlab}\\
\vspace{0.5cm}
You can choose to use the HTTPS or the SSH protocol.
\end{frame}
\section{Questions?}
\lastpagetemplate
\begin{frame}
......@@ -318,3 +349,18 @@ $ git pull ==> $ git fetch origin
\end{frame}
\end{document}
% move to commit graph lecture?
%% \begin{frame}
%% \frametitle{Remote branches}
%% You see code from remotes as {\em remote branches}:
%% \begin{itemize}
%% \item Remote branches are just branches prefixed with the remote name.
%% \item Communicate with remotes to update the remote branches.
%% \item You can setup a local branch to {\em track} a remote branch.
%% \end{itemize}
%% \pause
%% \bigskip
%% \includegraphics[width=10cm]{images/example}
%% \end{frame}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment