├── assets ├── images │ ├── tig.png │ ├── gitk.png │ ├── git-gui.png │ ├── kdiff3.png │ ├── github-clone.png │ ├── github-forking.png │ ├── gitmoon-collab.png │ ├── party-popper_1f389.png │ ├── git-mergetool-kdiff3-resolve.png │ ├── github-pull-request-create.png │ └── github-pull-request-submit.png └── diagrams │ ├── git-logo-2color.svg │ ├── git-logo-small.svg │ ├── remote-pull.svg │ ├── remote-add.svg │ ├── undo-modified.svg │ └── dias.svg ├── .gitignore ├── .gitmodules ├── sections ├── outro.tex ├── course-introduction.tex ├── tags.tex ├── introduction.tex ├── remotes.tex ├── extras.tex ├── conflicts.tex ├── branches.tex └── getting-started.tex ├── index.tex ├── README.md ├── .github └── workflows │ └── main.yml ├── Makefile ├── gitworkshop.tex ├── handoutWithNotes.sty └── LICENSE /assets/images/tig.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/segfault-trainings/gitworkshop/HEAD/assets/images/tig.png -------------------------------------------------------------------------------- /assets/images/gitk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/segfault-trainings/gitworkshop/HEAD/assets/images/gitk.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # vim swap files 2 | *.swp 3 | 4 | # build directory 5 | build/ 6 | 7 | # generated PDFs 8 | *.pdf 9 | -------------------------------------------------------------------------------- /assets/images/git-gui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/segfault-trainings/gitworkshop/HEAD/assets/images/git-gui.png -------------------------------------------------------------------------------- /assets/images/kdiff3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/segfault-trainings/gitworkshop/HEAD/assets/images/kdiff3.png -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "project"] 2 | path = project 3 | url = https://github.com/segfault-trainings/gitmoon.git 4 | 5 | -------------------------------------------------------------------------------- /assets/images/github-clone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/segfault-trainings/gitworkshop/HEAD/assets/images/github-clone.png -------------------------------------------------------------------------------- /assets/images/github-forking.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/segfault-trainings/gitworkshop/HEAD/assets/images/github-forking.png -------------------------------------------------------------------------------- /assets/images/gitmoon-collab.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/segfault-trainings/gitworkshop/HEAD/assets/images/gitmoon-collab.png -------------------------------------------------------------------------------- /assets/images/party-popper_1f389.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/segfault-trainings/gitworkshop/HEAD/assets/images/party-popper_1f389.png -------------------------------------------------------------------------------- /sections/outro.tex: -------------------------------------------------------------------------------- 1 | \begin{frame} 2 | \frametitle{Happy hacking :-)} 3 | \vspace{8em} 4 | \Huge{Thank you for your attention !} 5 | \end{frame} 6 | -------------------------------------------------------------------------------- /assets/images/git-mergetool-kdiff3-resolve.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/segfault-trainings/gitworkshop/HEAD/assets/images/git-mergetool-kdiff3-resolve.png -------------------------------------------------------------------------------- /assets/images/github-pull-request-create.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/segfault-trainings/gitworkshop/HEAD/assets/images/github-pull-request-create.png -------------------------------------------------------------------------------- /assets/images/github-pull-request-submit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/segfault-trainings/gitworkshop/HEAD/assets/images/github-pull-request-submit.png -------------------------------------------------------------------------------- /index.tex: -------------------------------------------------------------------------------- 1 | \input{../sections/course-introduction.tex} 2 | \input{../sections/introduction.tex} 3 | \input{../sections/getting-started.tex} 4 | \input{../sections/making-a-change.tex} 5 | \input{../sections/branches.tex} 6 | \input{../sections/tags.tex} 7 | \input{../sections/conflicts.tex} 8 | \input{../sections/remotes.tex} 9 | \input{../sections/extras.tex} 10 | \input{../sections/outro.tex} 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Git Workshop 2 | 3 | [![Actions Status](https://github.com/segfault-trainings/gitworkshop/workflows/CI/badge.svg)](https://github.com/segfault-trainings/gitworkshop/actions) 4 | 5 | This repository contains the slides and handouts for the **segfault-trainings Git workshop**. 6 | 7 | See the releases page [here](https://github.com/segfault-trainings/gitworkshop/releases) for pre-built slides and handouts. 8 | 9 | 10 | ## Build the slides and handout 11 | 12 | The easiest way to build the slides and handout is to use docker using the provided make target: 13 | 14 | ``` 15 | make with-docker 16 | ``` 17 | -------------------------------------------------------------------------------- /sections/course-introduction.tex: -------------------------------------------------------------------------------- 1 | \begin{frame} 2 | \frametitle{Agenda} 3 | \vspace{8em} 4 | 5 | \begin{description} 6 | \item 10:00 - 10:30 \textbf{Morning Break} 7 | \item 12:00 - 13:00 \textbf{Launch Break} 8 | \item 14:30 - 15:00 \textbf{Afternoon Break} 9 | \item 16:45 - 17:00 \textbf{Finish} 10 | \end{description} 11 | \end{frame} 12 | 13 | 14 | \begin{frame} 15 | \frametitle{Expectations} 16 | Answer these three questions for us to get to know you and what you expect from today. 17 | \begin{itemize} 18 | \item Who are you? 19 | \item Course expectations? 20 | \item Experience with git? 21 | \end{itemize} 22 | \end{frame} 23 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | container: 10 | image: blang/latex 11 | 12 | permissions: 13 | contents: write 14 | steps: 15 | - uses: actions/checkout@v3 16 | - name: Install inkscape and make 17 | run: | 18 | apt update 19 | apt install --yes inkscape make 20 | - name: Build Slides 21 | run: | 22 | make slides 23 | - name: Build Handout 24 | run: | 25 | make handout 26 | - name: Create Release 27 | if: startsWith(github.event.ref, 'refs/tags') 28 | uses: ncipollo/release-action@v1 29 | with: 30 | token: ${{ secrets.GITHUB_TOKEN }} 31 | name: Release ${{ github.ref_name }} 32 | artifacts: "GitWorkshop_Slides.pdf,GitWorkshop_Handout.pdf" 33 | generateReleaseNotes: true 34 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: build clean all builddir slides handout 2 | 3 | TMP := build 4 | 5 | SVGS := $(shell find assets/diagrams/* -maxdepth 0 -name '*.svg') 6 | PNGS = $(patsubst %.svg,$(TMP)/%.pdf,$(SVGS)) 7 | SLIDES = $(TMP)/assets/diagrams/git-forking-workflow-slide1.png \ 8 | $(TMP)/assets/diagrams/git-forking-workflow-slide2.png \ 9 | $(TMP)/assets/diagrams/git-forking-workflow-slide3.png \ 10 | $(TMP)/assets/diagrams/git-forking-workflow-slide4.png \ 11 | $(TMP)/assets/diagrams/git-forking-workflow-slide5.png 12 | 13 | 14 | all: slides handout 15 | test -d ~/public_html && cp -f gitworkshop.pdf gitworkshop\ Handout.pdf ~/public_html/ || true 16 | 17 | slides: build-dir $(PNGS) $(SLIDES) 18 | cd $(TMP) && pdflatex ../gitworkshop.tex 19 | cd $(TMP) && pdflatex ../gitworkshop.tex 20 | mv $(TMP)/gitworkshop.pdf GitWorkshop_Slides.pdf 21 | cp GitWorkshop_Slides.pdf GitWorkshop_Slides_$(shell date "+%Y-%m-%d").pdf 22 | 23 | handout: build-dir $(PNGS) $(SLIDES) 24 | cd $(TMP) && HANDOUT=1 pdflatex ../gitworkshop.tex 25 | cd $(TMP) && HANDOUT=1 pdflatex ../gitworkshop.tex 26 | mv $(TMP)/gitworkshop.pdf GitWorkshop_Handout.pdf 27 | cp GitWorkshop_Handout.pdf GitWorkshop_Handout_$(shell date "+%Y-%m-%d").pdf 28 | 29 | build-dir: 30 | mkdir -p $(TMP)/assets/diagrams 31 | 32 | $(TMP)/%.pdf: %.svg 33 | inkscape $< --without-gui --export-area-drawing --export-dpi=600 --export-pdf $@ 34 | 35 | $(TMP)/assets/diagrams/git-forking-workflow-slide%.png: assets/diagrams-multi/git-forking-workflow.svg 36 | inkscape --export-id "slide$*" --export-id-only assets/diagrams-multi/git-forking-workflow.svg --without-gui --export-dpi=600 --export-png $@ 37 | 38 | clean: 39 | rm -rf $(TMP) 40 | 41 | pull-image: 42 | docker pull blang/latex 43 | 44 | with-docker: 45 | docker run --rm -ti -v $(shell pwd):/data blang/latex sh -c "apt update && apt install -y inkscape && make" 46 | -------------------------------------------------------------------------------- /sections/tags.tex: -------------------------------------------------------------------------------- 1 | \section{Git Tags} 2 | \begin{frame}[fragile] 3 | \slidetitle 4 | 5 | This section covers the following topics: 6 | \begin{itemize} 7 | \item Tag a git commit 8 | \item Checking out tags 9 | \end{itemize} 10 | \end{frame} 11 | 12 | \subsection{Make a tag} 13 | \begin{frame}[fragile] 14 | \subslidetitle 15 | 16 | Select a short hash from the \cmd{git log --oneline} and let's make a tag: 17 | \begin{lstlisting} 18 | (*\textcolor[HTML]{18B2B2}{(master)}*) $ (*\textcolor[HTML]{0000AA}{git tag v0.1 ed009a}*) 19 | \end{lstlisting} 20 | \centerline{\includegraphics{assets/diagrams/git-tag.pdf}} 21 | 22 | \vspace{1em} 23 | Now we can created a branch based on a tag using \cmd{git switch} 24 | \begin{lstlisting} 25 | (*\textcolor[HTML]{18B2B2}{(master)}*) $ (*\textcolor[HTML]{0000AA}{git switch -c oldversion v0.1}*) 26 | Switched to a new branch 'oldversion' 27 | (*\textcolor[HTML]{18B2B2}{(oldversion)}*) $ 28 | \end{lstlisting} 29 | 30 | \end{frame} 31 | 32 | \subsection{Tag - Annotation} 33 | \begin{frame}[fragile] 34 | \subslidetitle 35 | It is even possible to add heavier tags, called annotations. To do this use \cmd{git tag -a}. 36 | 37 | \begin{lstlisting} 38 | (*\textcolor[HTML]{18B2B2}{(master)}*) $ (*\textcolor[HTML]{0000AA}{git tag -a v0.2 -m "example annotation tag"}*) 39 | \end{lstlisting} 40 | 41 | Annotated tags add the following features: 42 | \begin{itemize} 43 | \item Tag message similar to commit message 44 | \item Name and email of the tagger 45 | \item Creation date 46 | \end{itemize} 47 | 48 | We can look at them using \cmd{git show} 49 | \begin{lstlisting} 50 | (*\textcolor[HTML]{18B2B2}{(master)}*) $ (*\textcolor[HTML]{0000AA}{git show v0.2}*) 51 | tag v0.2 52 | Tagger: Tux Penguin 53 | Date: Tue Dec 1 03:17:04 2015 +0100 54 | 55 | example annotation tag 56 | ... 57 | \end{lstlisting} 58 | 59 | \end{frame} 60 | 61 | \subsection{Summary} 62 | \begin{frame}[fragile] 63 | \subslidetitle 64 | What we've learned in this chapter: 65 | \begin{itemize} 66 | \item What a Tag is 67 | \item Ways to tag a commit 68 | \end{itemize} 69 | \end{frame} 70 | -------------------------------------------------------------------------------- /sections/introduction.tex: -------------------------------------------------------------------------------- 1 | \section{Introduction} 2 | \begin{frame} 3 | \slidetitle 4 | The scope of this workshop covers: 5 | \begin{itemize} 6 | \item The concepts of git 7 | \item The usage of git (tool independent) 8 | \item Understanding git workflows 9 | \end{itemize} 10 | 11 | \pause 12 | \vspace{1em} 13 | Workshop strategy: 14 | \begin{itemize} 15 | \item Hands-on workshop on an example project 16 | \item Learning-by-doing 17 | \end{itemize} 18 | 19 | \pause 20 | \vspace{1em} 21 | Required skills: 22 | \begin{itemize} 23 | \item Basic usage of the command line 24 | \item Use a text editor (Vim) 25 | \item Type what is written on the slides :) 26 | \end{itemize} 27 | 28 | \vspace{1em} 29 | Note: This workshop takes about 8 hours (hopefully!) 30 | \end{frame} 31 | 32 | \subsection{Version Control Systems} 33 | \begin{frame} 34 | \subslidetitle 35 | 36 | \textbf{Why do we use Version Control Systems?} 37 | \pause 38 | \\ 39 | \begin{itemize} 40 | \item complete change history of \textbf{every} file 41 | \item navigate in history 42 | \item traceability 43 | \item working in a team (branching, merging, ...) 44 | \item ... 45 | \end{itemize} 46 | \end{frame} 47 | 48 | \subsection{History} 49 | \begin{frame} 50 | \subslidetitle 51 | 52 | \textbf{Version Control Systems (VCS)} 53 | \pause 54 | \\ 55 | \begin{tabular}{lp{6cm}r} 56 | \textbf{1982} & Revision Control System (RCS) & GNU GPL \\ 57 | \pause 58 | \textbf{1990} & Concurrent Versions System (CVS) & GNU GPL \\ 59 | \pause 60 | \textbf{1992} & Rational ClearCase & proprietary \\ 61 | \pause 62 | \textbf{1995} & Perforce & proprietary \\ 63 | \pause 64 | \textbf{2000} & Apache Subversion (SVN) & Apache \\ 65 | \end{tabular} 66 | \end{frame} 67 | 68 | \subsection{History} 69 | \begin{frame} 70 | \subslidetitle 71 | \textbf{Distributed Version Control Systems (DVCS)} 72 | \pause 73 | \\ 74 | \begin{tabular}{lp{6cm}r} 75 | \textbf{2000} & BitKeeper & proprietary \\ 76 | \pause 77 | \textbf{2001} & GNU arch & GNU GPL \\ 78 | \pause 79 | \textbf{2003} & Monotone & GNU GPL \\ 80 | \pause 81 | \textbf{2005} & git & GNU GPL \\ 82 | \pause 83 | \textbf{2005} & GNU Bazaar & GNU GPL \\ 84 | \pause 85 | \textbf{2005} & Mercurial & GNU GPL \\ 86 | \pause 87 | \end{tabular} 88 | 89 | Linus Torvalds created git in order to replace BitKeeper which changed the license in 2005. 90 | \end{frame} 91 | 92 | \subsection{About git} 93 | \begin{frame} 94 | \subslidetitle 95 | The term 'git' is British slang describing a person that is: 96 | \begin{itemize} 97 | \item unpleasant 98 | \item annoying 99 | \item childish 100 | \end{itemize} 101 | 102 | \pause 103 | \epigraph{``I'm an egotistical bastard, and I name all my projects after myself. First Linux, now git.''} 104 | {--- Linus Torvalds, 2007-06-14} 105 | \pause 106 | \epigraph{``Because my hatred of CVS has meant that I see Subversion as being the most pointless project ever started, because the whole slogan for the Subversion for a while was 'CVS done right' or something like that. And if you start with that kind of slogan, there is nowhere you can go. It's like, there is no way to do CVS right.''} 107 | {--- Linus Torvalds, Google Tech Talk 2007} 108 | \end{frame} 109 | 110 | \subsection{About git} 111 | \begin{frame} 112 | \subslidetitle 113 | \textbf{Design goals:} 114 | \pause 115 | \begin{itemize} 116 | \item Take Concurrent Versions System (CVS) as an example of what not to do; if in doubt, make the exact opposite decision 117 | \pause 118 | \item Support a distributed, BitKeeper-like workflow 119 | \pause 120 | \item Very strong safeguards against corruption, either accidental or malicious 121 | \pause 122 | \end{itemize} 123 | 124 | \vspace{2em} 125 | \textbf{Implementation:} 126 | \\ 127 | \pause 128 | \begin{tabular}{ll} 129 | Started: & 2005-04-03 \\ 130 | \pause 131 | Announced: &2005-04-06 \\ 132 | \pause 133 | Self Hosting: & 2005-04-07 (4d!) \\ 134 | \pause 135 | First Multi Branch Merge: & 2005-04-18 (15d!) 136 | \end{tabular} 137 | 138 | \end{frame} 139 | 140 | -------------------------------------------------------------------------------- /assets/diagrams/git-logo-2color.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | image/svg+xml -------------------------------------------------------------------------------- /assets/diagrams/git-logo-small.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | image/svg+xml -------------------------------------------------------------------------------- /gitworkshop.tex: -------------------------------------------------------------------------------- 1 | \documentclass[t,10pt]{beamer} 2 | \beamertemplatenavigationsymbolsempty 3 | 4 | \definecolor{GitRed}{RGB}{240, 60, 46} 5 | \setbeamercolor{title}{bg=GitRed,fg=white} 6 | \setbeamercolor{structure}{fg=black} 7 | \setbeamertemplate{section in toc shaded}[default][40] 8 | \setbeamercolor{itemize item}{fg=GitRed} 9 | \setbeamercolor{section in toc}{bg=GitRed,fg=white} 10 | \setcounter{tocdepth}{1} 11 | \setbeamertemplate{section in toc}{\inserttocsectionnumber.~\inserttocsection} 12 | 13 | % allow copy & paste, make nice tilde 14 | \usepackage[T1]{fontenc} 15 | % do not use bitmap font 16 | \usepackage{lmodern} 17 | 18 | % Quotations 19 | \usepackage{epigraph} 20 | \setlength\epigraphwidth{10cm} 21 | \setlength\epigraphrule{0pt} 22 | \renewcommand{\epigraphsize}{\normalsize} 23 | %\usepackage{etoolbox} 24 | %\makeatletter 25 | %\patchcmd{\epigraph}{\@epitext{#1}}{\itshape\@epitext{#1}}{}{} 26 | %\makeatother 27 | 28 | \usepackage{url} 29 | \usepackage{relsize} 30 | \usepackage{hyperref} 31 | \hypersetup{colorlinks=true, urlcolor=structure.fg, linkcolor=structure.fg} 32 | \renewcommand*{\UrlFont}{\ttfamily\footnotesize\relax} 33 | 34 | % disable ligatures to ensure that 35 | % hyphens (-) and especialy -- and --- 36 | % are shown as is and not rendert as en/em dash 37 | % important for cmds 38 | \usepackage{microtype} 39 | \DisableLigatures[-]{} 40 | 41 | %\usepackage{bold-extra} % cmtt 42 | %\renewcommand{\ttdefault}{cmtt} 43 | %\usepackage{lmodern} 44 | %\usepackage{pxfonts} % Palatino font 45 | %%\usepackage{txfonts} % Times font 46 | 47 | \makeatletter 48 | \newcommand\handoutmode[1]{ 49 | \ifnum1=0#1 50 | \gdef\beamer@currentmode{handout} 51 | \usepackage{../handoutWithNotes} 52 | \pgfpagesuselayout{4 on 1}[a4paper, landscape, border shrink=5mm] 53 | \setbeamertemplate{navigation symbols}{} 54 | \setbeamertemplate{headline}{% 55 | \leavevmode% 56 | \vspace{.5cm} 57 | } 58 | 59 | 60 | 61 | % define font of lstlisting 62 | \lstset{ 63 | basicstyle=\small\ttfamily\bfseries, %\tiny\ttfamily, 64 | tabsize=2, 65 | extendedchars=true, 66 | breaklines=true, 67 | %frame=single, 68 | %stringstyle=\ttfamily, 69 | showspaces=false, 70 | showtabs=false, 71 | xleftmargin=.25cm, 72 | %framextopmargin=0pt, 73 | %framexleftmargin=2pt, 74 | %framexrightmargin=2pt, 75 | %framexbottommargin=0pt, 76 | backgroundcolor=\color{white}, 77 | showstringspaces=false 78 | %morestring=[b][\color{blue}]", 79 | %morestring=[d][\color{blue}]', 80 | columns=fullflexible, 81 | escapeinside={(*}{*)}, 82 | keepspaces=true, 83 | upquote=true, 84 | commentstyle=\color{red}, 85 | keywordstyle=\color{blue}, 86 | rulecolor=\color{gray} 87 | % language=bash 88 | } 89 | %\lstloadlanguages{bash} 90 | \else 91 | \AtBeginSection[]{ 92 | \begin{frame}<*>{Outline} 93 | \hspace{1.2em} 94 | \begin{multicols}{2} 95 | \frametitle{Outline} 96 | \tableofcontents[currentsection] %,hideallsubsections] 97 | \end{multicols} 98 | \end{frame} 99 | } 100 | \addtocontents{toc}{\vskip -0.2cm} 101 | \setbeamertemplate{footline}[text line]{% 102 | \parbox{\linewidth}{\vspace*{-12pt}\textcolor{lightgray}{\inserttitle{} {\normalsize\ttfamily\textcopyright}\ 103 | https://github.com/segfault-trainings - Licensed for: CC-BY-SA-4.0 104 | \hfill \insertpagenumber/\pageref{LastPage}}} 105 | } 106 | \setbeamertemplate{navigation symbols}{} 107 | 108 | \setbeamercolor{title}{fg=white, bg=GitRed} 109 | \setbeamercolor{frametitle}{fg=white, bg=GitRed} 110 | 111 | \setbeamercolor{section in toc}{fg=black,bg=white} 112 | 113 | \setbeamertemplate{frametitle} 114 | { 115 | \nointerlineskip 116 | \begin{beamercolorbox}[sep=0.01cm,ht=1.8em,wd=\paperwidth]{frametitle} 117 | %\vbox{}\vskip-4ex% 118 | \hspace{.3cm}\strut\textbf\insertframetitle\strut 119 | %\vskip-0.8ex% 120 | \hfill$\vcenter{\hbox{\includegraphics{assets/diagrams/git-logo-small.pdf}}}$ 121 | \end{beamercolorbox} 122 | } 123 | 124 | % define font of lstlisting 125 | \definecolor{listingbackground}{rgb}{0,0,0} 126 | \lstset{ 127 | basicstyle=\small\ttfamily\bfseries\color{black}, %\tiny\ttfamily, 128 | tabsize=2, 129 | extendedchars=true, 130 | breaklines=true, 131 | frame=leftline, 132 | %stringstyle=\ttfamily, 133 | showspaces=false, 134 | showtabs=false, 135 | xleftmargin=.25cm, 136 | %framextopmargin=0pt, 137 | %framexleftmargin=2pt, 138 | %framexrightmargin=2pt, 139 | %framexbottommargin=0pt, 140 | backgroundcolor=\color{white}, 141 | showstringspaces=false 142 | %morestring=[b][\color{blue}]", 143 | %morestring=[d][\color{blue}]', 144 | columns=fullflexible, 145 | escapeinside={(*}{*)}, 146 | keepspaces=true, 147 | upquote=true, 148 | commentstyle=\color{red}, 149 | keywordstyle=\color{blue}, 150 | rulecolor=\color{gray} 151 | % language=bash 152 | } 153 | %\lstloadlanguages{bash} 154 | 155 | \fi 156 | } 157 | \makeatother 158 | 159 | \usepackage{catchfile} 160 | \newcommand{\getenv}[2][]{% 161 | \CatchFileEdef{\temp}{"|kpsewhich --var-value #2"}{}% 162 | \if\relax\detokenize{#1}\relax\temp\else\let#1\temp\fi} 163 | 164 | \usepackage{listings} 165 | 166 | \getenv[\HANDOUT]{HANDOUT} 167 | \handoutmode{\HANDOUT} 168 | 169 | \usepackage[utf8]{inputenc} 170 | \usepackage{multicol} 171 | \usepackage{color,soul} 172 | \usepackage{tabto} 173 | \usepackage{inconsolata} 174 | \usepackage{graphicx} 175 | \usepackage{wrapfig} 176 | \usepackage{upquote} 177 | \usepackage{vwcol} 178 | \usepackage{lastpage} 179 | 180 | 181 | % table spacings 182 | \renewcommand{\arraystretch}{1.5} 183 | 184 | %\setlength{\parskip}{10pt plus 1pt minus 1pt} 185 | 186 | \newcommand{\slidetitle}{\frametitle{\thesection. \secname}\vspace{1em}} 187 | \newcommand{\subslidetitle}{\frametitle{\thesection.\thesubsection\ \subsecname}\vspace{1em}} 188 | \newcommand{\subsubslidetitle}{\frametitle{\thesection.\thesubsection.\thesubsubsection\ \subsubsecname}\vspace{1em}} 189 | 190 | \newcommand{\cmd}[1]{\textcolor[HTML]{0000AA}{\texttt{\textbf{#1}}}} 191 | \newcommand{\option}[3][1cm]{\item[]{\usebeamercolor[structure.fg]{section in head}\texttt{#2}}\tabto{#1}#3} 192 | \newcommand{\opt}[3][2cm]{\item{\usebeamercolor[structure.fg]{section in head}\texttt{#2}}\tabto{#1}#3} 193 | 194 | \def\braces#1{[#1]} 195 | \def\lbrace#1{[#1} 196 | 197 | \newcounter{exercise} 198 | \newenvironment{exercise}[0] 199 | {\begin{enumerate}\setcounter{enumi}{\theexercise}} 200 | { \setcounter{exercise}{\theenumi}\end{enumerate}} 201 | 202 | % layout of title side 203 | \makeatletter 204 | \setbeamertemplate{title page} 205 | { 206 | \vspace{.6cm} 207 | \center \includegraphics{assets/diagrams/git-logo-2color.pdf} 208 | \vbox{} 209 | \vfill 210 | \begingroup 211 | \centering 212 | \begin{beamercolorbox}[sep=8pt,center]{title} 213 | \usebeamerfont{title}\bf{\Huge{workshop}}\par% 214 | \ifx\insertsubtitle\@empty% 215 | \else% 216 | \vskip0.25em% 217 | {\usebeamerfont{subtitle}\usebeamercolor[fg]{subtitle}\insertsubtitle\par}% 218 | \fi% 219 | \end{beamercolorbox}% 220 | \vskip.5em\par 221 | \begin{beamercolorbox}[sep=8pt,center]{author} 222 | \usebeamerfont{author}\insertauthor 223 | \end{beamercolorbox} 224 | \endgroup 225 | \vfill 226 | } 227 | \makeatother 228 | % end of layout of title side 229 | 230 | \setbeamerfont{author}{size=\smaller} 231 | \setbeamerfont{date}{size=\smaller} 232 | 233 | \begin{document} 234 | \title{git workshop} 235 | \author{ 236 | \textbf{Authors} \\ 237 | Contributors @ \url{https://github.com/segfault-trainings} \\ 238 | \url{https://github.com/segfault-trainings/gitworkshop/graphs/contributors} \\ 239 | \vspace{3em} 240 | \textbf{Licensed for:} Creative Commons Attribution Share Alike 4.0 International 241 | \textbf{Version:} \today 242 | } 243 | %\date{Version: \today} 244 | 245 | \frame{\titlepage} 246 | 247 | \input{../index.tex} 248 | 249 | \end{document} 250 | 251 | -------------------------------------------------------------------------------- /sections/remotes.tex: -------------------------------------------------------------------------------- 1 | \section{Git remotes} 2 | \begin{frame}[fragile] 3 | \slidetitle 4 | This section covers the following topics: 5 | \begin{itemize} 6 | \item Git remote repository concept 7 | \item Working with remotes and forks 8 | \item Collaborate on a Git repository 9 | \end{itemize} 10 | \end{frame} 11 | 12 | \subsection{Remote repositories} 13 | \begin{frame}[fragile] 14 | \subslidetitle 15 | Git has the concept of \textit{remote repositories}, 16 | which are just clones of the same repository located 17 | somewhere else. \\ 18 | 19 | The simplest case of a remote is the \textbf{origin}, 20 | created with a \cmd{git clone}: 21 | 22 | \vspace{3em} 23 | \centerline{\includegraphics{assets/diagrams/remote-concept.pdf}} 24 | \end{frame} 25 | 26 | \subsection{Show remotes} 27 | \begin{frame}[fragile] 28 | \subslidetitle 29 | We can use the \cmd{git remote show} command to have a look at the configured remotes: 30 | \begin{lstlisting} 31 | $ (*\textcolor[HTML]{0000AA}{git remote show}*) 32 | origin 33 | 34 | $ (*\textcolor[HTML]{0000AA}{git remote show origin}*) 35 | * remote origin 36 | Fetch URL: https://github.com/segfault-trainings/gitmoon.git 37 | Push URL: https://github.com/segfault-trainings/gitmoon.git 38 | HEAD branch: master 39 | Remote branch: 40 | master tracked 41 | Local branch configured for 'git pull': 42 | master merges with remote master 43 | Local ref configured for 'git push': 44 | master pushes to master (up to date) 45 | \end{lstlisting} 46 | \end{frame} 47 | 48 | \subsection{Forking Workflow} 49 | \begin{frame}[fragile] 50 | \subslidetitle 51 | 52 | Now let's get our hands dirty in Open Source! \\ 53 | \vspace{1em} 54 | 55 | Our goal is to: 56 | \begin{itemize} 57 | \item Use the \textit{Forking Workflow} 58 | \item Contribute a change to a repository on \href{https://github.com}{GitHub} 59 | \end{itemize} 60 | 61 | \centerline{\includegraphics[width=\textwidth]{../assets/images/gitmoon-collab.png}} 62 | 63 | \end{frame} 64 | 65 | \subsection{Forking Workflow} 66 | \begin{frame}[fragile] 67 | \subslidetitle 68 | Forking Workflow 69 | \centerline{\includegraphics[width=\textwidth]{assets/diagrams/git-forking-workflow-slide1.png}} 70 | 71 | \vspace{2em} 72 | \begin{itemize} 73 | \item Every contributor has it's own copy (fork) of the repo 74 | \item Contribute with Pull Requests 75 | \item Most often used in Open Source 76 | \end{itemize} 77 | 78 | \end{frame} 79 | 80 | \subsection{Forking Workflow - Fork} 81 | \begin{frame}[fragile] 82 | \subslidetitle 83 | 84 | Let's create a Fork from the \textbf{gitmoon-collab} project using \href{https://github.com}{GitHub}: 85 | 86 | \vspace{2em} 87 | \centerline{\includegraphics[width=\textwidth]{../assets/images/github-forking.png}} 88 | 89 | \vspace{1em} 90 | Note: the repository is at \url{https://github.com/segfault-trainings/gitmoon-collab}. 91 | 92 | \end{frame} 93 | 94 | \subsection{Forking Workflow - Clone} 95 | \begin{frame}[fragile] 96 | \subslidetitle 97 | 98 | First, we need to \cmd{git clone} our forked repository from the URL provided by GitHub: 99 | 100 | \vspace{1em} 101 | \centerline{\includegraphics[width=\textwidth]{../assets/images/github-clone.png}} 102 | 103 | \vspace{1em} 104 | Note: Use HTTPS if you haven't setup an SSH key in your GitHub account for now. 105 | \end{frame} 106 | 107 | \subsection{Forking Workflow - Clone} 108 | \begin{frame}[fragile] 109 | \subslidetitle 110 | 111 | For the next step you should be outside the gitmoon project folder. 112 | 113 | \begin{lstlisting} 114 | $ cd ~ 115 | $ (*\textcolor[HTML]{0000AA}{git clone https://github.com//gitmoon-collab.git}*) 116 | ... 117 | 118 | $ (*\textcolor[HTML]{0000AA}{git remote show origin}*) 119 | * remote origin 120 | Fetch URL: https://github.com//gitmoon-collab.git 121 | Push URL: https://github.com//gitmoon-collab.git 122 | HEAD branch: master 123 | 124 | $ cd gitmoon-collab 125 | \end{lstlisting} 126 | 127 | \end{frame} 128 | 129 | \subsection{Forking Workflow - Change} 130 | \begin{frame}[fragile] 131 | \subslidetitle 132 | 133 | Let's contribute a new \textit{moon}! 134 | \vspace{1em} 135 | 136 | First we'll create a new feature branch: 137 | 138 | \begin{lstlisting} 139 | $ (*\textcolor[HTML]{0000AA}{git switch -c feature/add-new-moon}*) 140 | Switched to a new branch 'feature/add-new-moon' 141 | \end{lstlisting} 142 | 143 | Second, we make create a new file (\lstinline{moons/.js}) with a moon. 144 | 145 | \begin{lstlisting} 146 | new Moon("", ""); 147 | \end{lstlisting} 148 | 149 | And create a new commit: 150 | \begin{lstlisting} 151 | $ (*\textcolor[HTML]{0000AA}{git add moons/.js}*) 152 | $ (*\textcolor[HTML]{0000AA}{git commit -m "Add new Moon "}*) 153 | [feature/add-new-moon 4ab6f8c] Add new Moon 154 | 1 file changed, 1 insertions(+), 1 deletions(-) 155 | \end{lstlisting} 156 | 157 | \end{frame} 158 | 159 | \subsection{Forking Workflow - Push} 160 | \begin{frame}[fragile] 161 | \subslidetitle 162 | 163 | Let's \textit{push} the new branch and it's commits to our fork on GitHub using \cmd{git push}: 164 | 165 | \begin{lstlisting} 166 | $ (*\textcolor[HTML]{0000AA}{git push --set-upstream origin feature/add-new-moon}*) 167 | ... 168 | To https://github.com//gitmoon-collab.git 169 | 6275110..4ab6f8c feature/add-new-moon -> feature/add-new-moon 170 | \end{lstlisting} 171 | 172 | \centerline{\includegraphics{assets/diagrams/remote-push.pdf}} 173 | 174 | \end{frame} 175 | 176 | \subsection{Forking Workflow - Push} 177 | \begin{frame}[fragile] 178 | \subslidetitle 179 | Forking Workflow 180 | \centerline{\includegraphics[width=\textwidth]{assets/diagrams/git-forking-workflow-slide2.png}} 181 | 182 | \end{frame} 183 | 184 | \subsection{Forking Workflow - Pull Request} 185 | \begin{frame}[fragile] 186 | \subslidetitle 187 | 188 | This change is so valuable that we should contribute it back to the original repository. 189 | 190 | \vspace{1em} 191 | GitHub uses \textbf{Pull Requests (PR)} for that! Let's create one: 192 | 193 | \vspace{1em} 194 | \centerline{\includegraphics[width=\textwidth]{../assets/images/github-pull-request-create.png}} 195 | 196 | \end{frame} 197 | 198 | \subsection{Forking Workflow - Pull Request} 199 | \begin{frame}[fragile] 200 | \subslidetitle 201 | 202 | Always provide a good PR title and description! 203 | 204 | \vspace{1em} 205 | \centerline{\includegraphics[width=\textwidth]{../assets/images/github-pull-request-submit.png}} 206 | 207 | \end{frame} 208 | 209 | \subsection{Forking Workflow - Pull Request} 210 | \begin{frame}[fragile] 211 | \subslidetitle 212 | 213 | \vspace{8em} 214 | \begin{center} 215 | Let's wait a little for the maintainer to review and merge those PR! 216 | \end{center} 217 | 218 | \end{frame} 219 | 220 | \subsection{Forking Workflow - Pull Request} 221 | \begin{frame}[fragile] 222 | \subslidetitle 223 | Pushing your changes to your fork on Github. 224 | 225 | \vspace{2em} 226 | \centerline{\includegraphics[width=\textwidth]{assets/diagrams/git-forking-workflow-slide3.png}} 227 | 228 | \end{frame} 229 | 230 | \subsection{Forking Workflow - Upstream} 231 | \begin{frame}[fragile] 232 | \subslidetitle 233 | 234 | Now your fork is missing all the awesome commits your colleagues made. 235 | 236 | \vspace{2em} 237 | \centerline{\includegraphics[width=\textwidth]{assets/diagrams/git-forking-workflow-slide4.png}} 238 | 239 | \end{frame} 240 | 241 | \subsection{Forking Workflow - Upstream} 242 | \begin{frame}[fragile] 243 | \subslidetitle 244 | 245 | We want those tasty commits from our colleagues in our fork, too! 246 | 247 | We've seen that our clone only knows the origin remote pointing to our fork: 248 | 249 | \begin{lstlisting} 250 | $ (*\textcolor[HTML]{0000AA}{git remote show}*) 251 | origin 252 | \end{lstlisting} 253 | 254 | To pull those changes, we need to configure a second \textbf{upstream} remote 255 | to connect our clone to the repository we forked from: 256 | 257 | \begin{lstlisting} 258 | $ (*\textcolor[HTML]{0000AA}{git remote add upstream https://github.com/segfault-trainings/gitmoon-collab}*) 259 | 260 | $ (*\textcolor[HTML]{0000AA}{git remote show}*) 261 | origin 262 | upstream 263 | \end{lstlisting} 264 | 265 | \end{frame} 266 | 267 | \subsection{Forking Workflow - Upstream} 268 | \begin{frame}[fragile] 269 | \subslidetitle 270 | 271 | Our clone is now connected to two remotes: \textit{origin} and \textit{upstream}: 272 | 273 | \vspace{3em} 274 | \centerline{\includegraphics{assets/diagrams/remote-concept-with-upstream.pdf}} 275 | 276 | \vspace{1em} 277 | Note: We can only push to \textit{origin}, but not the \textit{upstream}, because 278 | we don't have permission to do so. 279 | 280 | \end{frame} 281 | 282 | \subsection{Forking Workflow - Rebase} 283 | \begin{frame}[fragile] 284 | \subslidetitle 285 | 286 | Let's fetch the latest changes from the \textit{upstream} remote: 287 | 288 | \begin{lstlisting} 289 | $ (*\textcolor[HTML]{0000AA}{git fetch upstream}*) 290 | \end{lstlisting} 291 | 292 | We can inspect the branches available on upstream: 293 | 294 | \begin{lstlisting} 295 | $ (*\textcolor[HTML]{0000AA}{git branch --remote}*) 296 | origin/master 297 | ... 298 | upstream/master 299 | \end{lstlisting} 300 | 301 | And rebase the local \lstinline{master} to the \lstinline{upstream/master} branch: 302 | 303 | \begin{lstlisting} 304 | $ (*\textcolor[HTML]{0000AA}{git switch master}*) 305 | $ (*\textcolor[HTML]{0000AA}{git rebase upstream/master}*) 306 | \end{lstlisting} 307 | 308 | Let's also update our fork on GitHub: 309 | 310 | \begin{lstlisting} 311 | $ (*\textcolor[HTML]{0000AA}{git push}*) 312 | \end{lstlisting} 313 | 314 | \end{frame} 315 | 316 | \subsection{Forking Workflow - Rebase} 317 | \begin{frame}[fragile] 318 | \subslidetitle 319 | Update your fork on Github. 320 | 321 | \vspace{2em} 322 | \centerline{\includegraphics[width=\textwidth]{assets/diagrams/git-forking-workflow-slide5.png}} 323 | 324 | \end{frame} 325 | 326 | \subsection{Forking Workflow - Profit \includegraphics[height=1em]{../assets/images/party-popper_1f389.png}} 327 | \begin{frame}[fragile] 328 | \subslidetitle 329 | 330 | \vspace{8em} 331 | \begin{center} 332 | We successfully contributed to an awesome Open Source project! \includegraphics[height=1em]{../assets/images/party-popper_1f389.png} 333 | \end{center} 334 | 335 | \end{frame} 336 | 337 | \subsection{Summary} 338 | \begin{frame}[fragile] 339 | \subslidetitle 340 | What we've learned in this chapter: 341 | \begin{itemize} 342 | \item What remotes are 343 | \item How to work with remotes 344 | \item How to apply the Forking Workflow in practice 345 | \end{itemize} 346 | \end{frame} 347 | -------------------------------------------------------------------------------- /sections/extras.tex: -------------------------------------------------------------------------------- 1 | \section{Extras} 2 | \begin{frame}[fragile] 3 | \slidetitle 4 | This section covers some advanced topics: 5 | \begin{itemize} 6 | \item Cleaning workspace 7 | \item Working with patches 8 | \item Search keywords 9 | \item ... 10 | \end{itemize} 11 | \end{frame} 12 | 13 | \subsection{What to commit and what not to commit} 14 | \begin{frame}[fragile] 15 | \slidetitle 16 | It's best practice to not commit: 17 | \begin{itemize} 18 | \item Generated Binaries 19 | \item Large files (Use \lstinline{git-lfs}) 20 | \item Your personal editor configuration 21 | \item passwords and other secrets 22 | \item ... 23 | \end{itemize} 24 | 25 | Note: Make use of the \lstinline{.gitignore} file! 26 | 27 | \end{frame} 28 | 29 | \subsection{Remove untracked files} 30 | \begin{frame}[fragile] 31 | \subslidetitle 32 | Tracking a project under git helps you to keep your workspace clean, after your compilation process generated some temporary files: 33 | 34 | \begin{lstlisting} 35 | (*\textcolor[HTML]{18B2B2}{(master)}*) $ (*\textcolor[HTML]{0000AA}{touch \$(echo "compile" | hexdump | head -n1)}*) 36 | (*\textcolor[HTML]{18B2B2}{(master)}*) $ (*\textcolor[HTML]{0000AA}{git status}*) 37 | On branch master 38 | ... 39 | (*\textcolor[HTML]{AA0000}{ 0000000}*) 40 | (*\textcolor[HTML]{AA0000}{ 0a65}*) 41 | (*\textcolor[HTML]{AA0000}{ 6c69}*) 42 | (*\textcolor[HTML]{AA0000}{ 6f63}*) 43 | (*\textcolor[HTML]{AA0000}{ 706d}*) 44 | ... 45 | \end{lstlisting} 46 | Now we would like to clean all this temporary files, using \cmd{git clean}: 47 | \begin{lstlisting} 48 | (*\textcolor[HTML]{18B2B2}{(master)}*) $ (*\textcolor[HTML]{0000AA}{git clean -df}*) 49 | Removing 0000000 50 | Removing 0a65 51 | ... 52 | \end{lstlisting} 53 | 54 | \end{frame} 55 | 56 | \subsection{Git protocols} 57 | \begin{frame}[fragile] 58 | \subslidetitle 59 | Git repositories can be accessed locally or over the network. 60 | \\ 61 | \vspace{1em} 62 | Various protocols are supported: 63 | \begin{itemize} 64 | \opt{{\bf ssh}} {{\bf normally used for read-write access}} 65 | \opt{http[s]} {good for read only access without password} 66 | \opt{local} {file system based} 67 | \opt{git} {git native protocol on port 9418} 68 | \opt{legacy} {ftp, rsync, ...} 69 | \end{itemize} 70 | \vspace{1em} 71 | 72 | SSH provides us the possibility to authenticate without having to enter the password on every request. 73 | \end{frame} 74 | 75 | \subsection{Configure SSH access} 76 | \begin{frame}[fragile] 77 | \subslidetitle 78 | Create a SSH key pair: 79 | \begin{lstlisting} 80 | $ (*\textcolor[HTML]{0000AA}{ssh-keygen -f \textasciitilde/.ssh/id\_rsa}*) 81 | Generating public/private rsa key pair. 82 | Enter passphrase (empty for no passphrase): (*\textcolor[HTML]{0000AA}{}*) 83 | Enter same passphrase again: (*\textcolor[HTML]{0000AA}{}*) 84 | Your identification has been saved in .../.ssh/id_rsa. 85 | Your public key has been saved in .../.ssh/id_rsa.pub. 86 | The key fingerprint is: 87 | 7e:f8:15:2a:b3:a2:9c:30:4e:c7:60:50:a4:d5:a9:82 user@host 88 | The key's randomart image is: 89 | +--[ RSA 2048]----+ 90 | | . . . | 91 | | . = = S | 92 | | = X * X O o | 93 | ... 94 | \end{lstlisting} 95 | \end{frame} 96 | 97 | \subsection{Configure SSH access} 98 | \begin{frame}[fragile] 99 | \subslidetitle 100 | Display your public key: 101 | \begin{lstlisting} 102 | $ (*\textcolor[HTML]{0000AA}{cat \textasciitilde/.ssh/id\_rsa.pub}*) 103 | ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDOmt7Y4H51gc2m 104 | GmZsFzES6shVLFLEJ/lFCTwyosWHYDaluK71nGCelp61oTocgf4N 105 | HBwTZmo0EZ1k0RHYt8Q3LF8e5fbC+dXt5E35XtkVFuUC7IG2/6fm 106 | NW41j3lw9UUVrOBDgx+QvvoCuRQaxNd4mRaLsRbj9WXt17hGuNNW 107 | ioKPWLSpw/4KHJ34hCrnliAQJ+jlW/0ieOooFp057diCka6Jn7BW 108 | jXHi8sWMxIfyPyV2+4Kt8OpChFNYjzaL5LMRRhMnvJ8zP5SFJB2q 109 | HP50zPYQ+gKoSda7GZedZRgD7gT7ir/u8X9HSpNyTNTafhp9+3Aj 110 | uUiYLTgtczTgYk/T user@host 111 | \end{lstlisting} 112 | 113 | This whole output can be added to the SSH access keys 114 | section in the web frontend of your git appliance. 115 | \end{frame} 116 | 117 | \subsection{Search with git} 118 | \begin{frame}[fragile] 119 | \subslidetitle 120 | Lost in search? It is just convenient to have \cmd{git grep}: 121 | \begin{lstlisting} 122 | (*\textcolor[HTML]{18B2B2}{(master)}*) $ (*\textcolor[HTML]{0000AA}{git grep moon.js}*) 123 | moon.html: 124 | \end{lstlisting} 125 | 126 | Or we can search commits that touch lines containing the keyword you are looking for using \cmd{git log --pickaxe-regexp}: 127 | \begin{lstlisting} 128 | (*\textcolor[HTML]{18B2B2}{(master)}*) $ (*\textcolor[HTML]{0000AA}{git log --oneline --abbrev --pickaxe-regex "*moon*"}*) 129 | (*\textcolor[HTML]{ae6617}{a3c399f}*) remove the blue moon 130 | (*\textcolor[HTML]{ae6617}{93ea12c}*) change the green moon color to red 131 | ... 132 | 39719c9 initial commit 133 | \end{lstlisting} 134 | 135 | Finally a option of \cmd{git branch} to search the branch a commit belongs to: 136 | \begin{lstlisting} 137 | (*\textcolor[HTML]{18B2B2}{(master)}*) $ (*\textcolor[HTML]{0000AA}{git branch --contains a3c399f}*) 138 | (*\textcolor[HTML]{00AA00}{* master}*) 139 | \end{lstlisting} 140 | \end{frame} 141 | 142 | \subsection{Finger pointing!?} 143 | \begin{frame}[fragile] 144 | \subslidetitle 145 | 146 | The \cmd{git blame} returns revision and author information per each line of a given file: 147 | \begin{lstlisting} 148 | (*\textcolor[HTML]{18B2B2}{(master)}*) $ (*\textcolor[HTML]{0000AA}{git blame moon.js}*) 149 | ... 150 | 0cf42e1 (Timo Furrer 22) // create moons 151 | 0cf42e1 (Timo Furrer 23) new Moon("green"); 152 | 0ba92c4 (Timo Furrer 24) new Moon("gray"); 153 | 0e213fb (Timo Furrer 25) new Moon("white"); 154 | ... 155 | \end{lstlisting} 156 | 157 | \end{frame} 158 | 159 | \subsection{Work with patches} 160 | \begin{frame}[fragile] 161 | \subslidetitle 162 | Remove the blue moon: 163 | \begin{lstlisting} 164 | (*\textcolor[HTML]{18B2B2}{(master)}*) $ (*\textcolor[HTML]{0000AA}{sed -i "/blue/d" moon.js}*) 165 | (*\textcolor[HTML]{18B2B2}{(master)}*) $ (*\textcolor[HTML]{0000AA}{git commit -a -m "remove the blue moon"}*) 166 | \end{lstlisting} 167 | 168 | The \cmd{git format-patch} generates patch file to be send to 3rd party collaborator, or mailing list: 169 | \begin{lstlisting} 170 | (*\textcolor[HTML]{18B2B2}{(master)}*) $ (*\textcolor[HTML]{0000AA}{git format-patch -1}*) 171 | 0001-remove-the-blue-moon.patch 172 | \end{lstlisting} 173 | 174 | \begin{lstlisting} 175 | (*\textcolor[HTML]{18B2B2}{(master)}*) $ (*\textcolor[HTML]{0000AA}{cat 0001-remove-the-blue-moon.patch}*) 176 | From 7afa035a39c2dc9648b182772eee06e3181ae24e Mon Sep 17 00:00:00 2001 177 | From: Eric Keller 178 | Date: Sun, 29 Nov 2015 10:06:27 +0000 179 | Subject: [PATCH] remove the blue moon 180 | ... 181 | // create moons 182 | new Moon("green"); 183 | -new Moon("blue"); 184 | new Moon("white"); 185 | ... 186 | \end{lstlisting} 187 | 188 | \end{frame} 189 | 190 | \subsection{Apply a patch} 191 | \begin{frame}[fragile] 192 | \subslidetitle 193 | First remove the last commit: 194 | \begin{lstlisting} 195 | (*\textcolor[HTML]{18B2B2}{(master)}*) $ (*\textcolor[HTML]{0000AA}{git reset --hard HEAD\textasciicircum1}*) 196 | \end{lstlisting} 197 | Create new no-blue branch in order to apply this patch 198 | \begin{lstlisting} 199 | (*\textcolor[HTML]{18B2B2}{(master)}*) $ (*\textcolor[HTML]{0000AA}{git switch -c no-blue}*) 200 | Switched to a new branch 'no-blue' 201 | \end{lstlisting} 202 | 203 | The \cmd{git am} command takes a list of patch to apply to the current working area: 204 | \begin{lstlisting} 205 | (*\textcolor[HTML]{18B2B2}{(no-blue)}*) $ (*\textcolor[HTML]{0000AA}{git am -3 0001-remove-the-blue-moon.patch}*) 206 | Applying: remove the blue moon 207 | \end{lstlisting} 208 | 209 | Note: As well as when merging branch the \cmd{git am} could potentially end up with conflict, therefore we would like to enforce a 3way-merge with the \cmd{-3} option. 210 | 211 | \end{frame} 212 | 213 | \subsection{Advanced undo} 214 | \begin{frame}[fragile] 215 | \subslidetitle 216 | 217 | Want to undo a rebase operation? You deleted an important file? Got interrupted in the middle of an octopus merge... Do not worry \cmd{git reflog} is here to help. 218 | 219 | \begin{lstlisting} 220 | (*\textcolor[HTML]{18B2B2}{(master)}*) $ (*\textcolor[HTML]{0000AA}{git reflog}*) 221 | (*\textcolor[HTML]{ae6617}{9ed88d3}*) HEAD@{0}: checkout: moving from death-star to master 222 | (*\textcolor[HTML]{ae6617}{429131d}*) HEAD@{1}: rebase finished: returning to refs/heads/death-star 223 | (*\textcolor[HTML]{ae6617}{429131d}*) HEAD@{2}: rebase: add death-star 224 | (*\textcolor[HTML]{ae6617}{9ed88d3}*) HEAD@{3}: rebase: checkout master 225 | (*\textcolor[HTML]{ae6617}{9dd4b4b}*) HEAD@{4}: checkout: moving from master to death-star 226 | (*\textcolor[HTML]{ae6617}{9ed88d3}*) HEAD@{5}: commit: snow white comment 227 | \end{lstlisting} 228 | 229 | You use reflog in combination with the \cmd{git reset --hard HEAD@\{4\}} command. 230 | \end{frame} 231 | 232 | \subsection{Git submodules} 233 | \begin{frame}[fragile] 234 | \subslidetitle 235 | Git offers the possibility to include other git repositories in a subdirectory of a project. 236 | \\ 237 | \vspace{1em} 238 | The following commands deal with submodules: 239 | \begin{itemize} 240 | \item \cmd{git clone URL --recursive} 241 | \item \cmd{git submodule add URL PATH} 242 | \item \cmd{git submodule update} 243 | \item \cmd{git submodule sync} 244 | \end{itemize} 245 | \vspace{1em} 246 | Note: the main project can commit the subdirectory and fix the commit of the submodule. 247 | \end{frame} 248 | 249 | \subsection{Git aliases} 250 | \begin{frame}[fragile] 251 | \subslidetitle 252 | 253 | Git allows to create aliases for commands. 254 | \\ 255 | \vspace{1em} 256 | Example: 257 | instead of typing \cmd{git status} we want to type \cmd{git st}. 258 | \\ 259 | \vspace{1em} 260 | Define aliases: 261 | 262 | \begin{lstlisting} 263 | git config --global alias.st = status 264 | git config --global alias.sw = switch 265 | git config --global alias.ci = commit 266 | git config --global alias.br = branch 267 | \end{lstlisting} 268 | 269 | \end{frame} 270 | 271 | \subsection{Git config} 272 | \begin{frame}[fragile] 273 | \subslidetitle 274 | 275 | Lets look at our global config with \cmd{cat \char`~/.gitconfig} 276 | \begin{lstlisting} 277 | [user] 278 | name = Tux Penguin 279 | email = tux@penguin 280 | 281 | [color] 282 | diff = auto 283 | status = auto 284 | branch = auto 285 | grep = auto 286 | 287 | [alias] 288 | l = log --graph --pretty=format:'%C(yellow)%h%C(cyan)%d%Creset %s %C(white)- %an, %ar%Creset' 289 | ll = log --stat --abbrev-commit 290 | \end{lstlisting} 291 | 292 | \cmd{git config --list} will show the currently active config. 293 | \end{frame} 294 | -------------------------------------------------------------------------------- /handoutWithNotes.sty: -------------------------------------------------------------------------------- 1 | % Copyright 2009 by Guido Diepen 2 | % Parts provided by Edson Valle 3 | % 4 | % This file may be distributed and/or modified 5 | % 6 | % 1. under the LaTeX Project Public License and/or 7 | % 2. under the GNU Public License. 8 | % 9 | % Changelog 10 | % 20091202 - Added "1 on 1 with notes" layout, provided by Harald Welte 11 | % 20091108 - Added "2 on 1 with notes landscape" layout, provided by Edson Valle 12 | % 20091104 - Added "3 on 1 with notes" layout 13 | % 20091104 - Added "2 on 1 with notes" layout 14 | % 20091104 - Added "1 on 1 with notes landscape" layout, provided by Edson Valle 15 | % 20090101 - Initial Version 16 | 17 | \RequirePackage{pgfpages} 18 | \pgfpagesdeclarelayout{1 on 1 with notes landscape} { 19 | \edef\pgfpageoptionheight{\the\paperwidth} 20 | \edef\pgfpageoptionwidth{\the\paperheight} 21 | \edef\pgfpageoptionborder{0pt} 22 | } 23 | { 24 | \setkeys{pgfpagesuselayoutoption}{landscape} 25 | \pgfpagesphysicalpageoptions 26 | {% 27 | logical pages=2,% 28 | physical height=\pgfpageoptionheight,% 29 | physical width=\pgfpageoptionwidth,% 30 | % last logical shipout=3% 31 | last logical shipout=1% 32 | } 33 | 34 | \pgfpageslogicalpageoptions{1} 35 | {% 36 | scale=1.2, 37 | center=\pgfpoint{.3\pgfphysicalwidth}{.5\pgfphysicalheight}% 38 | }% 39 | 40 | 41 | 42 | \pgfpageslogicalpageoptions{2} 43 | {% 44 | border shrink=\pgfpageoptionborder,% 45 | resized width=.45\pgfphysicalwidth,% 46 | resized height=.45\pgfphysicalheight,% 47 | center=\pgfpoint{.78\pgfphysicalwidth}{.6\pgfphysicalheight},% 48 | copy from=2 49 | }% 50 | 51 | \AtBeginDocument{ 52 | \newbox\notesbox 53 | \setbox\notesbox=\vbox{ 54 | \hsize=\paperwidth 55 | \vskip-1in\hskip-1in\vbox{ 56 | \vskip1cm 57 | Notes\vskip1cm 58 | \hrule width\paperwidth\vskip1cm 59 | \hrule width\paperwidth\vskip1cm 60 | \hrule width\paperwidth\vskip1cm 61 | \hrule width\paperwidth\vskip1cm 62 | \hrule width\paperwidth\vskip1cm 63 | \hrule width\paperwidth\vskip1cm 64 | \hrule width\paperwidth\vskip1cm 65 | \hrule width\paperwidth\vskip1cm 66 | \hrule width\paperwidth\vskip1cm 67 | \hrule width\paperwidth\vskip1cm 68 | \hrule width\paperwidth\vskip1cm 69 | \hrule width\paperwidth} 70 | } 71 | \pgfpagesshipoutlogicalpage{2}\copy\notesbox 72 | 73 | 74 | } 75 | } 76 | 77 | \pgfpagesdeclarelayout{4 on 1 with notes} { 78 | \edef\pgfpageoptionheight{\the\paperheight} 79 | \edef\pgfpageoptionwidth{\the\paperwidth} 80 | \edef\pgfpageoptionborder{0pt} 81 | } 82 | { 83 | \pgfpagesphysicalpageoptions 84 | {% 85 | logical pages=8,% 86 | physical height=\pgfpageoptionheight,% 87 | physical width=\pgfpageoptionwidth,% 88 | % last logical shipout=3% 89 | last logical shipout=4% 90 | } 91 | 92 | \pgfpageslogicalpageoptions{1} 93 | {% 94 | scale=.70, 95 | center=\pgfpoint{.25\pgfphysicalwidth}{.875\pgfphysicalheight}% 96 | }% 97 | \pgfpageslogicalpageoptions{2} 98 | {% 99 | scale=.70, 100 | center=\pgfpoint{.25\pgfphysicalwidth}{.625\pgfphysicalheight}% 101 | }% 102 | 103 | \pgfpageslogicalpageoptions{3} 104 | {% 105 | scale=.70, 106 | center=\pgfpoint{.25\pgfphysicalwidth}{.375\pgfphysicalheight}% 107 | }% 108 | 109 | \pgfpageslogicalpageoptions{4} 110 | {% 111 | scale=.70, 112 | center=\pgfpoint{.25\pgfphysicalwidth}{.125\pgfphysicalheight}% 113 | }% 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | \pgfpageslogicalpageoptions{5} 123 | {% 124 | border shrink=\pgfpageoptionborder,% 125 | resized width=.5\pgfphysicalwidth,% 126 | resized height=.3333\pgfphysicalheight,% 127 | center=\pgfpoint{.75\pgfphysicalwidth}{.875\pgfphysicalheight},% 128 | copy from=5 129 | }% 130 | \pgfpageslogicalpageoptions{6} 131 | {% 132 | border shrink=\pgfpageoptionborder,% 133 | resized width=.5\pgfphysicalwidth,% 134 | resized height=.3333\pgfphysicalheight,% 135 | center=\pgfpoint{.75\pgfphysicalwidth}{.625\pgfphysicalheight},% 136 | copy from=6 137 | }% 138 | \pgfpageslogicalpageoptions{7} 139 | {% 140 | border shrink=\pgfpageoptionborder,% 141 | resized width=.5\pgfphysicalwidth,% 142 | resized height=.3333\pgfphysicalheight,% 143 | center=\pgfpoint{.75\pgfphysicalwidth}{.375\pgfphysicalheight},% 144 | copy from=7 145 | }% 146 | \pgfpageslogicalpageoptions{8} 147 | {% 148 | border shrink=\pgfpageoptionborder,% 149 | resized width=.5\pgfphysicalwidth,% 150 | resized height=.3333\pgfphysicalheight,% 151 | center=\pgfpoint{.75\pgfphysicalwidth}{.125\pgfphysicalheight},% 152 | copy from=8 153 | }% 154 | \AtBeginDocument{ 155 | \newbox\notesbox 156 | \setbox\notesbox=\vbox{ 157 | \hsize=\paperwidth 158 | \vskip-1in\hskip-1in\vbox{ 159 | \vskip1.8cm 160 | \textcolor{lightgray}{\hrule width\paperwidth}\vskip.8cm 161 | \textcolor{lightgray}{\hrule width\paperwidth}\vskip.8cm 162 | \textcolor{lightgray}{\hrule width\paperwidth}\vskip.8cm 163 | \textcolor{lightgray}{\hrule width\paperwidth}\vskip.8cm 164 | \textcolor{lightgray}{\hrule width\paperwidth}\vskip.8cm 165 | \textcolor{lightgray}{\hrule width\paperwidth}\vskip.8cm 166 | \textcolor{lightgray}{\hrule width\paperwidth}\vskip.8cm 167 | \textcolor{lightgray}{\hrule width\paperwidth}\vskip.8cm 168 | \textcolor{lightgray}{\hrule width\paperwidth}\vskip.8cm 169 | \textcolor{lightgray}{\hrule width\paperwidth} 170 | } 171 | } 172 | \pgfpagesshipoutlogicalpage{5}\copy\notesbox 173 | \pgfpagesshipoutlogicalpage{6}\copy\notesbox 174 | \pgfpagesshipoutlogicalpage{7}\copy\notesbox 175 | \pgfpagesshipoutlogicalpage{8}\copy\notesbox 176 | } 177 | } 178 | 179 | 180 | 181 | \pgfpagesdeclarelayout{2 on 1 with notes} { 182 | \edef\pgfpageoptionheight{\the\paperheight} 183 | \edef\pgfpageoptionwidth{\the\paperwidth} 184 | \edef\pgfpageoptionborder{0pt} 185 | } 186 | { 187 | \pgfpagesphysicalpageoptions 188 | {% 189 | logical pages=4,% 190 | physical height=\pgfpageoptionheight,% 191 | physical width=\pgfpageoptionwidth,% 192 | % last logical shipout=3% 193 | last logical shipout=2% 194 | } 195 | 196 | \pgfpageslogicalpageoptions{1} 197 | {% 198 | scale=.70, 199 | center=\pgfpoint{.25\pgfphysicalwidth}{.67\pgfphysicalheight}% 200 | }% 201 | \pgfpageslogicalpageoptions{2} 202 | {% 203 | scale=.70, 204 | center=\pgfpoint{.25\pgfphysicalwidth}{.33\pgfphysicalheight}% 205 | }% 206 | 207 | 208 | \pgfpageslogicalpageoptions{3} 209 | {% 210 | border shrink=\pgfpageoptionborder,% 211 | resized width=.5\pgfphysicalwidth,% 212 | resized height=.5\pgfphysicalheight,% 213 | center=\pgfpoint{.75\pgfphysicalwidth}{.67\pgfphysicalheight},% 214 | copy from=3 215 | }% 216 | \pgfpageslogicalpageoptions{4} 217 | {% 218 | border shrink=\pgfpageoptionborder,% 219 | resized width=.5\pgfphysicalwidth,% 220 | resized height=.5\pgfphysicalheight,% 221 | center=\pgfpoint{.75\pgfphysicalwidth}{.33\pgfphysicalheight},% 222 | copy from=4 223 | }% 224 | 225 | \AtBeginDocument{ 226 | \newbox\notesbox 227 | \setbox\notesbox=\vbox{ 228 | \hsize=\paperwidth 229 | \vskip-1in\hskip-1in\vbox{ 230 | \vskip1cm 231 | Notes\vskip1cm 232 | \hrule width\paperwidth\vskip1cm 233 | \hrule width\paperwidth\vskip1cm 234 | \hrule width\paperwidth\vskip1cm 235 | \hrule width\paperwidth\vskip1cm 236 | \hrule width\paperwidth\vskip1cm 237 | \hrule width\paperwidth\vskip1cm 238 | \hrule width\paperwidth} 239 | } 240 | \pgfpagesshipoutlogicalpage{3}\copy\notesbox 241 | \pgfpagesshipoutlogicalpage{4}\copy\notesbox 242 | } 243 | } 244 | 245 | 246 | \pgfpagesdeclarelayout{3 on 1 with notes} { 247 | \edef\pgfpageoptionheight{\the\paperheight} 248 | \edef\pgfpageoptionwidth{\the\paperwidth} 249 | \edef\pgfpageoptionborder{0pt} 250 | } 251 | { 252 | \pgfpagesphysicalpageoptions 253 | {% 254 | logical pages=6,% 255 | physical height=\pgfpageoptionheight,% 256 | physical width=\pgfpageoptionwidth,% 257 | % last logical shipout=3% 258 | last logical shipout=3% 259 | } 260 | 261 | \pgfpageslogicalpageoptions{1} 262 | {% 263 | scale=.70, 264 | center=\pgfpoint{.25\pgfphysicalwidth}{.82\pgfphysicalheight}% 265 | }% 266 | \pgfpageslogicalpageoptions{2} 267 | {% 268 | scale=.70, 269 | center=\pgfpoint{.25\pgfphysicalwidth}{.50\pgfphysicalheight}% 270 | }% 271 | \pgfpageslogicalpageoptions{3} 272 | {% 273 | scale=.70, 274 | center=\pgfpoint{.25\pgfphysicalwidth}{.18\pgfphysicalheight}% 275 | }% 276 | 277 | 278 | \pgfpageslogicalpageoptions{4} 279 | {% 280 | border shrink=\pgfpageoptionborder,% 281 | resized width=.5\pgfphysicalwidth,% 282 | resized height=.5\pgfphysicalheight,% 283 | center=\pgfpoint{.75\pgfphysicalwidth}{.82\pgfphysicalheight},% 284 | copy from=4 285 | }% 286 | \pgfpageslogicalpageoptions{5} 287 | {% 288 | border shrink=\pgfpageoptionborder,% 289 | resized width=.5\pgfphysicalwidth,% 290 | resized height=.5\pgfphysicalheight,% 291 | center=\pgfpoint{.75\pgfphysicalwidth}{.50\pgfphysicalheight},% 292 | copy from=5 293 | }% 294 | \pgfpageslogicalpageoptions{6} 295 | {% 296 | border shrink=\pgfpageoptionborder,% 297 | resized width=.5\pgfphysicalwidth,% 298 | resized height=.5\pgfphysicalheight,% 299 | center=\pgfpoint{.75\pgfphysicalwidth}{.18\pgfphysicalheight},% 300 | copy from=6 301 | }% 302 | 303 | \AtBeginDocument{ 304 | \newbox\notesbox 305 | \setbox\notesbox=\vbox{ 306 | \hsize=\paperwidth 307 | \vskip-1in\hskip-1in\vbox{ 308 | \vskip1cm 309 | Notes\vskip1cm 310 | \hrule width\paperwidth\vskip1cm 311 | \hrule width\paperwidth\vskip1cm 312 | \hrule width\paperwidth\vskip1cm 313 | \hrule width\paperwidth\vskip1cm 314 | \hrule width\paperwidth\vskip1cm 315 | \hrule width\paperwidth\vskip1cm 316 | \hrule width\paperwidth} 317 | } 318 | \pgfpagesshipoutlogicalpage{4}\copy\notesbox 319 | \pgfpagesshipoutlogicalpage{5}\copy\notesbox 320 | \pgfpagesshipoutlogicalpage{6}\copy\notesbox 321 | } 322 | } 323 | 324 | 325 | 326 | 327 | 328 | \pgfpagesdeclarelayout{2 on 1 with notes landscape} { 329 | \edef\pgfpageoptionheight{\the\paperheight} 330 | \edef\pgfpageoptionwidth{\the\paperwidth} 331 | \edef\pgfpageoptionborder{0pt} 332 | } 333 | { 334 | \setkeys{pgfpagesuselayoutoption}{landscape} 335 | \pgfpagesphysicalpageoptions 336 | {% 337 | logical pages=4,% 338 | physical height=\pgfpageoptionheight,% 339 | physical width=\pgfpageoptionwidth,% 340 | % last logical shipout=3% 341 | last logical shipout=2% 342 | } 343 | 344 | \pgfpageslogicalpageoptions{1} 345 | {% 346 | scale=1, 347 | center=\pgfpoint{.3\pgfphysicalwidth}{.75\pgfphysicalheight}% 348 | }% 349 | \pgfpageslogicalpageoptions{2} 350 | {% 351 | scale=1, 352 | center=\pgfpoint{.3\pgfphysicalwidth}{.25\pgfphysicalheight}% 353 | }% 354 | 355 | 356 | 357 | \pgfpageslogicalpageoptions{3} 358 | {% 359 | border shrink=\pgfpageoptionborder,% 360 | resized width=.7\pgfphysicalwidth,% 361 | resized height=.4\pgfphysicalheight,% 362 | center=\pgfpoint{.75\pgfphysicalwidth}{.3\pgfphysicalheight},% 363 | copy from=3 364 | }% 365 | 366 | \pgfpageslogicalpageoptions{4} 367 | {% 368 | border shrink=\pgfpageoptionborder,% 369 | resized width=.7\pgfphysicalwidth,% 370 | resized height=.4\pgfphysicalheight,% 371 | center=\pgfpoint{.75\pgfphysicalwidth}{.8\pgfphysicalheight},% 372 | copy from=4 373 | }% 374 | 375 | \AtBeginDocument{ 376 | \newbox\notesbox 377 | \setbox\notesbox=\vbox{ 378 | \hsize=\paperwidth 379 | \vskip-1in\hskip-1in\vbox{ 380 | \vskip1cm 381 | Notes\vskip1cm 382 | \hrule width\paperwidth\vskip1cm 383 | \hrule width\paperwidth\vskip1cm 384 | \hrule width\paperwidth\vskip1cm 385 | \hrule width\paperwidth\vskip1cm 386 | \hrule width\paperwidth\vskip1cm 387 | \hrule width\paperwidth\vskip1cm 388 | %\hrule width\paperwidth\vskip1cm 389 | %\hrule width\paperwidth\vskip1cm 390 | \hrule width\paperwidth\vskip1cm 391 | \hrule width\paperwidth\vskip1cm 392 | \hrule width\paperwidth\vskip1cm 393 | \hrule width\paperwidth} 394 | } 395 | \pgfpagesshipoutlogicalpage{3}\copy\notesbox 396 | \pgfpagesshipoutlogicalpage{4}\copy\notesbox 397 | 398 | 399 | } 400 | } 401 | 402 | 403 | 404 | \pgfpagesdeclarelayout{1 on 1 with notes} { 405 | \edef\pgfpageoptionheight{\the\paperwidth} 406 | \edef\pgfpageoptionwidth{\the\paperheight} 407 | \edef\pgfpageoptionborder{0pt} 408 | } 409 | { 410 | \setkeys{pgfpagesuselayoutoption}{portrait} 411 | \pgfpagesphysicalpageoptions 412 | {% 413 | logical pages=2,% 414 | physical height=\pgfpageoptionheight,% 415 | physical width=\pgfpageoptionwidth,% 416 | % last logical shipout=3% 417 | last logical shipout=1% 418 | } 419 | 420 | \pgfpageslogicalpageoptions{1} 421 | {% 422 | scale=1.5, 423 | center=\pgfpoint{.5\pgfphysicalwidth}{.73\pgfphysicalheight}% 424 | }% 425 | 426 | 427 | 428 | \pgfpageslogicalpageoptions{2} 429 | {% 430 | border shrink=\pgfpageoptionborder,% 431 | resized width=\pgfphysicalwidth,% 432 | resized height=\pgfphysicalheight,% 433 | center=\pgfpoint{.5\pgfphysicalwidth}{.25\pgfphysicalheight},% 434 | copy from=2 435 | }% 436 | 437 | \AtBeginDocument{ 438 | \newbox\notesbox 439 | \setbox\notesbox=\vbox{ 440 | \hsize=.85\paperwidth 441 | \vskip-1in\hskip-1in\vbox{ 442 | \vskip1cm 443 | Notes\vskip5mm 444 | \hrule width\paperwidth\vskip5mm 445 | \hrule width\paperwidth\vskip5mm 446 | \hrule width\paperwidth\vskip5mm 447 | \hrule width\paperwidth\vskip5mm 448 | \hrule width\paperwidth\vskip5mm 449 | \hrule width\paperwidth\vskip5mm 450 | \hrule width\paperwidth\vskip5mm 451 | \hrule width\paperwidth\vskip5mm 452 | \hrule width\paperwidth\vskip5mm 453 | \hrule width\paperwidth\vskip5mm 454 | \hrule width\paperwidth\vskip5mm 455 | \hrule width\paperwidth\vskip5mm 456 | \hrule width\paperwidth\vskip5mm 457 | \hrule width\paperwidth\vskip5mm 458 | \hrule width\paperwidth} 459 | } 460 | \pgfpagesshipoutlogicalpage{2}\copy\notesbox 461 | 462 | 463 | } 464 | } 465 | 466 | 467 | 468 | 469 | 470 | -------------------------------------------------------------------------------- /sections/conflicts.tex: -------------------------------------------------------------------------------- 1 | \section{Handling conflicts} 2 | \begin{frame}[fragile] 3 | \slidetitle 4 | This section covers the following topics: 5 | \begin{itemize} 6 | \item Solve merge conflicts 7 | \item Solve rebase conflicts 8 | \item 3 way merge 9 | \end{itemize} 10 | \end{frame} 11 | 12 | \subsection{Prepare a merge conflict} 13 | \begin{frame}[fragile] 14 | \subslidetitle 15 | Switch to the master branch 16 | \begin{lstlisting} 17 | (*\textcolor[HTML]{18B2B2}{(oldversion)}*) $ (*\textcolor[HTML]{0000AA}{git switch master}*) 18 | \end{lstlisting} 19 | Implement the change in \cmd{moon.js} following this diff: 20 | \begin{lstlisting} 21 | (*\textcolor[HTML]{18B2B2}{@@ -4,7 +4,7 @@}*) 22 | // create moons 23 | new Moon("white"); 24 | (*\textcolor[HTML]{AA0000}{-}*)(*\textcolor[HTML]{AA0000}{new Moon("green");}*) 25 | (*\textcolor[HTML]{00AA00}{+}*)(*\textcolor[HTML]{00AA00}{new Moon("red");}*) 26 | 27 | // Function to setup the scene for our awesome moons :) 28 | \end{lstlisting} 29 | 30 | Commit your changes on master: 31 | \begin{lstlisting} 32 | (*\textcolor[HTML]{18B2B2}{(master)}*) $ (*\textcolor[HTML]{0000AA}{git commit -a -m "change the green moon to red"}*) 33 | \end{lstlisting} 34 | 35 | \end{frame} 36 | 37 | \subsection{Prepare a merge conflict} 38 | \begin{frame}[fragile] 39 | \subslidetitle 40 | 41 | Switch to the branch third-moon: 42 | \begin{lstlisting} 43 | (*\textcolor[HTML]{18B2B2}{(master)}*) $ (*\textcolor[HTML]{0000AA}{git switch third-moon}*) 44 | \end{lstlisting} 45 | 46 | Add a comment to the green moon like defined in the following diff: 47 | \begin{lstlisting} 48 | (*\textcolor[HTML]{18B2B2}{@@ -4,7 +4,7 @@}*) 49 | // create moons 50 | new Moon("white"); 51 | (*\textcolor[HTML]{AA0000}{-}*)(*\textcolor[HTML]{AA0000}{new Moon("green");}*) 52 | (*\textcolor[HTML]{00AA00}{+}*)(*\textcolor[HTML]{00AA00}{new Moon("green"); // the moon was sooo green!}*) 53 | 54 | // Function to setup the scene for our awesome moons :) 55 | \end{lstlisting} 56 | 57 | Commit your changes: 58 | \begin{lstlisting} 59 | (*\textcolor[HTML]{18B2B2}{(third-moon)}*) $ (*\textcolor[HTML]{0000AA}{git commit -a -m "comment on green moon"}*) 60 | \end{lstlisting} 61 | \end{frame} 62 | 63 | \subsection{Prepare a merge conflict} 64 | \begin{frame}[fragile] 65 | \subslidetitle 66 | 67 | Let's merge the third-moon branch to master: 68 | \begin{lstlisting} 69 | (*\textcolor[HTML]{18B2B2}{(third-moon)}*) $ (*\textcolor[HTML]{0000AA}{git switch master}*) 70 | Switched to branch 'master' 71 | Your branch is ahead of 'origin/master' by 11 commits. 72 | (use "git push" to publish your local commits) 73 | 74 | (*\textcolor[HTML]{18B2B2}{(master)}*) $ (*\textcolor[HTML]{0000AA}{git merge third-moon}*) 75 | Auto-merging moon.js 76 | CONFLICT (content): Merge conflict in moon.js 77 | Automatic merge failed; fix conflicts and then commit the result. 78 | \end{lstlisting} 79 | \centerline{\includegraphics{assets/diagrams/merge-conflict.pdf}} 80 | \vspace{0.5em} 81 | Here we go, our first conflict, keep calm, do not panic, we are using \cmd{git}! 82 | \end{frame} 83 | 84 | \subsection{Displaying conflicts} 85 | \begin{frame}[fragile] 86 | \subslidetitle 87 | 88 | First we want to inspect which files have conflicts, using \cmd{git status}: 89 | \begin{lstlisting} 90 | (*\textcolor[HTML]{18B2B2}{(master|MERGING)}*) $ (*\textcolor[HTML]{0000AA}{git status}*) 91 | On branch master 92 | Your branch is ahead of 'origin/master' by 11 commit. 93 | (use "git push" to publish your local commits) 94 | 95 | You have unmerged paths. 96 | (fix conflicts and run "git commit") 97 | (use "git merge --abort" to abort the merge) 98 | 99 | Unmerged paths: 100 | (use "git add ..." to mark resolution) 101 | (*\textcolor[HTML]{AA0000}{both modified: moon.js}*) 102 | 103 | no changes added to commit (use "git add" and/or "git commit -a") 104 | \end{lstlisting} 105 | \end{frame} 106 | 107 | \subsection{Displaying conflicts} 108 | \begin{frame}[fragile] 109 | \subslidetitle 110 | 111 | Then we want can display the merge conflict, using \cmd{git diff}: 112 | \begin{lstlisting} 113 | (*\textcolor[HTML]{18B2B2}{(master|MERGING)}*) $ (*\textcolor[HTML]{0000AA}{git diff}*) 114 | diff --cc moon.js 115 | index 72886cb,861507e..0000000 116 | --- a/moon.js 117 | +++ b/moon.js 118 | (*\textcolor[HTML]{18B2B2}{@@@ -4,7 -4,7 +4,11 @@@}*) 119 | // create moons 120 | new Moon("white"); 121 | (*\textcolor[HTML]{00AA00}{++}*)(*\textcolor[HTML]{00AA00}{<<<<<<< HEAD}*) 122 | (*\textcolor[HTML]{00AA00}{+}*) (*\textcolor[HTML]{00AA00}{new Moon("red");}*) 123 | (*\textcolor[HTML]{00AA00}{++}*)(*\textcolor[HTML]{00AA00}{=======}*) 124 | (*\textcolor[HTML]{00AA00}{+}*) (*\textcolor[HTML]{00AA00}{new Moon("green"); // the moon was sooo green!}*) 125 | (*\textcolor[HTML]{00AA00}{++}*)(*\textcolor[HTML]{00AA00}{>>>>>>> third-moon}*) 126 | 127 | // Function to setup the scene for our awesome moons :) 128 | \end{lstlisting} 129 | \end{frame} 130 | 131 | \subsection{Displaying conflicts} 132 | \begin{frame}[fragile] 133 | \subslidetitle 134 | 135 | The \textcolor[HTML]{0000AA}{blue conflict markers} were inserted by git: 136 | \begin{lstlisting} 137 | (*\textcolor[HTML]{18B2B2}{(master|MERGING)}*) $ (*\textcolor[HTML]{0000AA}{git diff}*) 138 | diff --cc moon.js 139 | index 72886cb,861507e..0000000 140 | --- a/moon.js 141 | +++ b/moon.js 142 | (*\textcolor[HTML]{18B2B2}{@@@ -4,7 -4,7 +4,11 @@@}*) 143 | // create moons 144 | new Moon("blue"); 145 | new Moon("white"); 146 | (*\textcolor[HTML]{0000AA}{++}*)(*\textcolor[HTML]{0000AA}{<<<<<<< HEAD}*) 147 | (*\textcolor[HTML]{00AA00}{+}*) (*\textcolor[HTML]{00AA00}{new Moon("red");}*) 148 | (*\textcolor[HTML]{0000AA}{++}*)(*\textcolor[HTML]{0000AA}{=======}*) 149 | (*\textcolor[HTML]{00AA00}{+}*) (*\textcolor[HTML]{00AA00}{new Moon("green"); // the moon was sooo green!}*) 150 | (*\textcolor[HTML]{0000AA}{++}*)(*\textcolor[HTML]{0000AA}{>>>>>>> third-moon}*) 151 | 152 | // Function to setup the scene for our awesome moons :) 153 | \end{lstlisting} 154 | \end{frame} 155 | 156 | \subsection{Displaying conflicts} 157 | \begin{frame}[fragile] 158 | \subslidetitle 159 | 160 | The \textcolor[HTML]{0000AA}{HEAD} represents the changes in master (our current branch): 161 | \begin{lstlisting} 162 | (*\textcolor[HTML]{18B2B2}{(master|MERGING)}*) $ (*\textcolor[HTML]{0000AA}{git diff}*) 163 | diff --cc moon.js 164 | index 72886cb,861507e..0000000 165 | --- a/moon.js 166 | +++ b/moon.js 167 | (*\textcolor[HTML]{18B2B2}{@@@ -4,7 -4,7 +4,11 @@@}*) 168 | // create moons 169 | new Moon("blue"); 170 | new Moon("white"); 171 | (*\textcolor[HTML]{0000AA}{++}*)(*\textcolor[HTML]{0000AA}{<<<<<<< HEAD}*) 172 | (*\textcolor[HTML]{0000AA}{+}*) (*\textcolor[HTML]{0000AA}{new Moon("red");}*) 173 | (*\textcolor[HTML]{0000AA}{++}*)(*\textcolor[HTML]{0000AA}{=======}*) 174 | (*\textcolor[HTML]{00AA00}{+}*) (*\textcolor[HTML]{00AA00}{new Moon("green"); // the moon was sooo green!}*) 175 | (*\textcolor[HTML]{00AA00}{++}*)(*\textcolor[HTML]{00AA00}{>>>>>>> third-moon}*) 176 | 177 | // Function to setup the scene for our awesome moons :) 178 | \end{lstlisting} 179 | \end{frame} 180 | 181 | 182 | \subsection{Displaying conflicts} 183 | \begin{frame}[fragile] 184 | \subslidetitle 185 | 186 | The \textcolor[HTML]{0000AA}{third-moon} represents the changes in the branch 187 | we want to merge into master: 188 | \begin{lstlisting} 189 | (*\textcolor[HTML]{18B2B2}{(master|MERGING)}*) $ (*\textcolor[HTML]{0000AA}{git diff}*) 190 | diff --cc moon.js 191 | index 72886cb,861507e..0000000 192 | --- a/moon.js 193 | +++ b/moon.js 194 | (*\textcolor[HTML]{18B2B2}{@@@ -4,7 -4,7 +4,11 @@@}*) 195 | // create moons 196 | new Moon("blue"); 197 | new Moon("white"); 198 | (*\textcolor[HTML]{00AA00}{++}*)(*\textcolor[HTML]{00AA00}{<<<<<<< HEAD}*) 199 | (*\textcolor[HTML]{00AA00}{+}*) (*\textcolor[HTML]{00AA00}{new Moon("red");}*) 200 | (*\textcolor[HTML]{0000AA}{++}*)(*\textcolor[HTML]{0000AA}{=======}*) 201 | (*\textcolor[HTML]{0000AA}{+}*) (*\textcolor[HTML]{0000AA}{new Moon("green"); // the moon was sooo green!}*) 202 | (*\textcolor[HTML]{0000AA}{++}*)(*\textcolor[HTML]{0000AA}{>>>>>>> third-moon}*) 203 | 204 | // Function to setup the scene for our awesome moons :) 205 | \end{lstlisting} 206 | \end{frame} 207 | 208 | \subsection{Resolving conflicts} 209 | \begin{frame}[fragile] 210 | \subslidetitle 211 | 212 | Open the conflicting \cmd{moon.js} file and resolve the conflicts to 213 | get the following diff: 214 | 215 | \begin{lstlisting} 216 | diff --cc moon.js 217 | index 1b9f39e,0d8ce3c..0000000 218 | --- a/moon.js 219 | +++ b/moon.js 220 | @@@ -16,7 -16,7 +16,7 @@@ let ctx = 221 | }; 222 | 223 | // create moons 224 | (*\textcolor[HTML]{AA0000}{-}*) (*\textcolor[HTML]{AA0000}{new Moon("red");}*) 225 | (*\textcolor[HTML]{AA0000}{-}*)(*\textcolor[HTML]{AA0000}{new Moon("green"); // the moon was sooo green!}*) 226 | (*\textcolor[HTML]{00AA00}{++}*)(*\textcolor[HTML]{00AA00}{new Moon("red"); // the strawberry moon!}*) 227 | 228 | // Function to setup the scene for our awesome moons :) 229 | setup(); 230 | \end{lstlisting} 231 | 232 | \end{frame} 233 | 234 | \subsection{Preparing merge commit} 235 | \begin{frame}[fragile] 236 | \subslidetitle 237 | 238 | The files are still in conflict state: 239 | \begin{lstlisting} 240 | (*\textcolor[HTML]{18B2B2}{(master|MERGING)}*) $ (*\textcolor[HTML]{0000AA}{git status}*) 241 | On branch master 242 | Your branch is ahead of 'origin/master' by 11 commit. 243 | (use "git push" to publish your local commits) 244 | 245 | You have unmerged paths. 246 | (fix conflicts and run "git commit") 247 | (use "git merge --abort" to abort the merge) 248 | 249 | Unmerged paths: 250 | (use "git add ..." to mark resolution) 251 | (*\textcolor[HTML]{AA0000}{both modified: moon.js}*) 252 | 253 | no changes added to commit (use "git add" and/or "git commit -a") 254 | \end{lstlisting} 255 | \end{frame} 256 | 257 | \subsection{Preparing merge commit} 258 | \begin{frame}[fragile] 259 | \subslidetitle 260 | 261 | Add the file to mark the conflicts as resolved: 262 | \begin{lstlisting} 263 | (*\textcolor[HTML]{18B2B2}{(master|MERGING)}*) $ (*\textcolor[HTML]{0000AA}{git add moon.js}*) 264 | (*\textcolor[HTML]{18B2B2}{(master|MERGING)}*) $ (*\textcolor[HTML]{0000AA}{git status}*) 265 | On branch master 266 | Your branch is ahead of 'origin/master' by 11 commit. 267 | (use "git push" to publish your local commits) 268 | 269 | All conflicts fixed but you are still merging. 270 | (use "git commit" to conclude merge) 271 | 272 | Changes to be committed: 273 | (*\textcolor[HTML]{00AA00}{modified: moon.js}*) 274 | \end{lstlisting} 275 | \end{frame} 276 | 277 | \subsection{Finishing merge commit} 278 | \begin{frame}[fragile] 279 | \subslidetitle 280 | 281 | Commit the changes, save and exit the editor: 282 | \begin{lstlisting} 283 | (*\textcolor[HTML]{18B2B2}{(master|MERGING)}*) $ (*\textcolor[HTML]{0000AA}{git commit}*) 284 | (*\textcolor[HTML]{18B2B2}{(master)}*) $ (*\textcolor[HTML]{0000AA}{git log --oneline -n 1}*) 285 | (*\textcolor[HTML]{ae6617}{682eb22}*) Merge branch 'third-moon' 286 | \end{lstlisting} 287 | \end{frame} 288 | 289 | \subsection{Preparing rebase conflict} 290 | \begin{frame}[fragile] 291 | \subslidetitle 292 | 293 | Create a new \cmd{death-star} branch: 294 | \begin{lstlisting} 295 | (*\textcolor[HTML]{18B2B2}{(master)}*)$ (*\textcolor[HTML]{0000AA}{git switch -c death-star master}*) 296 | Switched to a new branch 'death-star' 297 | \end{lstlisting} 298 | 299 | Implement the change in \cmd{moon.js} following this diff: 300 | 301 | \begin{lstlisting} 302 | (*\textcolor[HTML]{AA0000}{-}*)(*\textcolor[HTML]{AA0000}{new Moon("white");}*) 303 | (*\textcolor[HTML]{00AA00}{+}*)(*\textcolor[HTML]{00AA00}{new Moon("black");}*) 304 | new Moon("red"); 305 | \end{lstlisting} 306 | 307 | Commit the change: 308 | \begin{lstlisting} 309 | (*\textcolor[HTML]{18B2B2}{(death-star)}*)$ (*\textcolor[HTML]{0000AA}{git commit -a -m "add death-star"}*) 310 | [death-star 2670288] add death-star 311 | 1 file changed, 1 insertion(+), 1 deletion(-) 312 | \end{lstlisting} 313 | \end{frame} 314 | 315 | \subsection{Preparing rebase conflict} 316 | \begin{frame}[fragile] 317 | \subslidetitle 318 | Change to the master branch: 319 | \begin{lstlisting} 320 | (*\textcolor[HTML]{18B2B2}{(death-star)}*)$ (*\textcolor[HTML]{0000AA}{git switch master}*) 321 | \end{lstlisting} 322 | 323 | Modify the moon.js file accordingly: 324 | \begin{lstlisting} 325 | (*\textcolor[HTML]{AA0000}{-}*)(*\textcolor[HTML]{AA0000}{new Moon("white");}*) 326 | (*\textcolor[HTML]{00AA00}{+}*)(*\textcolor[HTML]{00AA00}{new Moon("white"); // as snow}*) 327 | new Moon("red"); 328 | \end{lstlisting} 329 | 330 | Commit the change: 331 | \begin{lstlisting} 332 | (*\textcolor[HTML]{18B2B2}{(master)}*)$ (*\textcolor[HTML]{0000AA}{git commit -a -m "snow white comment"}*) 333 | [master 9307b0a] snow white comment 334 | 1 file changed, 1 insertion(+), 1 deletion(-) 335 | \end{lstlisting} 336 | Change to the death-star branch: 337 | \begin{lstlisting} 338 | (*\textcolor[HTML]{18B2B2}{(death-star)}*)$ (*\textcolor[HTML]{0000AA}{git switch death-star}*) 339 | \end{lstlisting} 340 | \end{frame} 341 | 342 | \subsection{Rebasing with conflict} 343 | \begin{frame}[fragile] 344 | \subslidetitle 345 | \begin{lstlisting} 346 | (*\textcolor[HTML]{18B2B2}{(death-star)}*)$ (*\textcolor[HTML]{0000AA}{git rebase master}*) 347 | First, rewinding head to replay your work on top of it. 348 | Applying: add death-star 349 | Using index info to reconstruct a base tree... 350 | M moon.js 351 | Falling back to patching base and 3-way merge... 352 | Auto-merging moon.js 353 | CONFLICT (content): Merge conflict in moon.js 354 | error: Failed to merge in the changes. 355 | Patch failed at 0001 add death-star 356 | \end{lstlisting} 357 | 358 | \vspace{1em} 359 | \centerline{\includegraphics{assets/diagrams/rebase-conflict.pdf}} 360 | \end{frame} 361 | 362 | \subsection{Display conflict} 363 | \begin{frame}[fragile] 364 | \subslidetitle 365 | First we want to display the conflicting file with \cmd{git diff}: 366 | \begin{lstlisting} 367 | (*\textcolor[HTML]{18B2B2}{(death-star|REBASE 1/1)}*) $ (*\textcolor[HTML]{0000AA}{git diff}*) 368 | diff --cc moon.js 369 | index 72886cb,861507e..0000000 370 | --- a/moon.js 371 | +++ b/moon.js 372 | (*\textcolor[HTML]{18B2B2}{@@@ -4,7 -4,7 +4,11 @@@}*) 373 | (*\textcolor[HTML]{00AA00}{++}*)(*\textcolor[HTML]{00AA00}{<<<<<<< d5d25c1555e1137d3ecd3bf335d3ac3515605bf4}*) 374 | (*\textcolor[HTML]{00AA00}{+}*) (*\textcolor[HTML]{00AA00}{new Moon("white"); // as snow}*) 375 | (*\textcolor[HTML]{00AA00}{++}*)(*\textcolor[HTML]{00AA00}{=======}*) 376 | (*\textcolor[HTML]{00AA00}{+}*) (*\textcolor[HTML]{00AA00}{new Moon("black");}*) 377 | (*\textcolor[HTML]{00AA00}{++}*)(*\textcolor[HTML]{00AA00}{>>>>>>> add death-star}*) 378 | 379 | \end{lstlisting} 380 | \end{frame} 381 | 382 | \subsection{Resolve rebase conflict} 383 | \begin{frame}[fragile] 384 | \subslidetitle 385 | Resolve the conflict editing the \cmd{moon.js} file: 386 | 387 | \begin{lstlisting} 388 | (*\textcolor[HTML]{AA0000}{-}*)(*\textcolor[HTML]{AA0000}{<<<<<<< d5d25c1555e1137d3ecd3bf335d3ac3515605bf4}*) 389 | (*\textcolor[HTML]{AA0000}{-}*)(*\textcolor[HTML]{AA0000}{new Moon("white"); // as snow}*) 390 | (*\textcolor[HTML]{AA0000}{-}*)(*\textcolor[HTML]{AA0000}{=======}*) 391 | new Moon("black"); 392 | (*\textcolor[HTML]{AA0000}{-}*)(*\textcolor[HTML]{AA0000}{>>>>>>> add death-star}*) 393 | \end{lstlisting} 394 | 395 | \vspace{1em} 396 | Use \cmd{git add} to stage the changes: 397 | \begin{lstlisting} 398 | (*\textcolor[HTML]{18B2B2}{(death-star|REBASE 1/1)}*) $ (*\textcolor[HTML]{0000AA}{git add moon.js}*) 399 | \end{lstlisting} 400 | %\end{frame} 401 | 402 | %\subsection{Finish rebasing} 403 | %\begin{frame}[fragile] 404 | %\subslidetitle 405 | Continue the rebase: 406 | \begin{lstlisting} 407 | (*\textcolor[HTML]{18B2B2}{(death-star|REBASE 1/1)}*) $ (*\textcolor[HTML]{0000AA}{git rebase --continue}*) 408 | Applying: add death-star 409 | \end{lstlisting} 410 | \end{frame} 411 | 412 | \subsection{Summary} 413 | \begin{frame}[fragile] 414 | \subslidetitle 415 | What we've learned in this chapter: 416 | \begin{itemize} 417 | \item Why conflicts happen 418 | \item How to resolve conflicts 419 | \end{itemize} 420 | \end{frame} 421 | -------------------------------------------------------------------------------- /sections/branches.tex: -------------------------------------------------------------------------------- 1 | \section{Git Branches} 2 | \begin{frame}[fragile] 3 | \slidetitle 4 | 5 | This section covers the following topics: 6 | \begin{itemize} 7 | \item Git Workflows 8 | \item Create and delete branches 9 | \item Work with branches 10 | \item Rebase branches 11 | \item Merge branches 12 | \item Cherry-Pick commits 13 | \end{itemize} 14 | \end{frame} 15 | 16 | \subsection{The master branch} 17 | \begin{frame}[fragile] 18 | \subslidetitle 19 | 20 | With git, you are always working on a branch and the default git branch is called \cmd{master}. 21 | \newline \vspace{1em} 22 | \centerline{\includegraphics{assets/diagrams/branch-master.pdf}} 23 | 24 | \vspace{1.2em} 25 | Note: \cmd{HEAD} always points to the current branch. 26 | 27 | \end{frame} 28 | 29 | \subsection{Workflows / Branching Models} 30 | \begin{frame}[fragile] 31 | \subslidetitle 32 | Centralized Workflow 33 | \centerline{\includegraphics{assets/diagrams/git-centralized-workflow.pdf}} 34 | 35 | \vspace{2em} 36 | \begin{itemize} 37 | \item Only the \lstinline{master} branch is used 38 | \item First rebase, then push 39 | \item Often used to transition from old-ish VCS 40 | \end{itemize} 41 | \end{frame} 42 | 43 | \subsection{Workflows / Branching Models} 44 | \begin{frame}[fragile] 45 | \subslidetitle 46 | Feature Branch Workflow 47 | \centerline{\includegraphics{assets/diagrams/git-workflow.pdf}} 48 | 49 | \vspace{2em} 50 | \begin{itemize} 51 | \item Development in small feature branches 52 | \item Chance for Pull Requests 53 | \item No broken code on \lstinline{master} 54 | \end{itemize} 55 | \end{frame} 56 | 57 | \subsection{Workflows / Branching Models} 58 | \begin{frame}[fragile] 59 | \subslidetitle 60 | Gitflow Workflow 61 | \centerline{\includegraphics[width=\textwidth]{assets/diagrams/git-gitflow-workflow.pdf}} 62 | 63 | \begin{itemize} 64 | \item Like \textit{Feature Branch Workflow} 65 | \item Assign special roles to certain branches 66 | \end{itemize} 67 | 68 | \end{frame} 69 | 70 | \subsection{Creating branches} 71 | \begin{frame}[fragile] 72 | \subslidetitle 73 | 74 | To create a new \cmd{foo} branch, append the branch name to the \cmd{git branch} command: 75 | \begin{lstlisting} 76 | (*\textcolor[HTML]{18B2B2}{(master)}*) $ (*\textcolor[HTML]{0000AA}{git branch foo}*) 77 | \end{lstlisting} 78 | 79 | The \cmd{git branch} command lists all your local branches: 80 | \begin{lstlisting} 81 | (*\textcolor[HTML]{18B2B2}{(master)}*) $ (*\textcolor[HTML]{0000AA}{git branch}*) 82 | foo 83 | * (*\textcolor[HTML]{00AA00}{master}*) 84 | \end{lstlisting} 85 | \vspace{1em} 86 | \centerline{\includegraphics{assets/diagrams/branch-create.pdf}} 87 | \vspace{1em} 88 | Note: The branch you are currently on is marked with an asterisk (*). 89 | \end{frame} 90 | 91 | \subsection{Switching to branch} 92 | \begin{frame}[fragile] 93 | \subslidetitle 94 | The \cmd{git switch} command is used to change the current branch: 95 | \begin{lstlisting} 96 | (*\textcolor[HTML]{18B2B2}{(master)}*) $ (*\textcolor[HTML]{0000AA}{git switch foo}*) 97 | Switched to branch 'foo' 98 | 99 | (*\textcolor[HTML]{18B2B2}{(foo)}*) $ (*\textcolor[HTML]{0000AA}{git branch}*) 100 | * (*\textcolor[HTML]{00AA00}{foo}*) 101 | master 102 | \end{lstlisting} 103 | 104 | \vspace{1em} 105 | The \cmd{git switch} command with \cmd{-c} option creates a new branch and automatically switches to it: 106 | \begin{lstlisting} 107 | (*\textcolor[HTML]{18B2B2}{(foo)}*) $ (*\textcolor[HTML]{0000AA}{git switch -c bar}*) 108 | Switched to a new branch 'bar' 109 | 110 | (*\textcolor[HTML]{18B2B2}{(bar)}*) $ (*\textcolor[HTML]{0000AA}{git branch}*) 111 | * (*\textcolor[HTML]{00AA00}{bar}*) 112 | foo 113 | master 114 | \end{lstlisting} 115 | \end{frame} 116 | 117 | \subsection{Deleting a branch} 118 | \begin{frame}[fragile] 119 | \subslidetitle 120 | To delete an existing branch use the \cmd{-d} or \cmd{-D} (force) flag: 121 | \begin{lstlisting} 122 | (*\textcolor[HTML]{18B2B2}{(bar)}*) $ (*\textcolor[HTML]{0000AA}{git switch master}*) 123 | 124 | (*\textcolor[HTML]{18B2B2}{(master)}*) $ (*\textcolor[HTML]{0000AA}{git branch -d foo bar}*) 125 | Deleted branch foo (was c974445). 126 | Deleted branch bar (was 9adadac). 127 | 128 | (*\textcolor[HTML]{18B2B2}{(master)}*) $ (*\textcolor[HTML]{0000AA}{git branch}*) 129 | * (*\textcolor[HTML]{00AA00}{master}*) 130 | \end{lstlisting} 131 | 132 | \vspace{1em} 133 | Note: you cannot delete the branch you are currently working on. 134 | \end{frame} 135 | 136 | \subsection{Rebasing} 137 | \begin{frame}[fragile] 138 | \subslidetitle 139 | Rebase puts a branch on top of an other: 140 | \centerline{\includegraphics{assets/diagrams/branch-rebase.pdf}} 141 | \end{frame} 142 | 143 | \subsection{Prepare for rebase exercise} 144 | \begin{frame}[fragile] 145 | \subslidetitle 146 | 147 | Start to create a new fix-title branch: 148 | \begin{lstlisting} 149 | (*\textcolor[HTML]{18B2B2}{(master)}*) $ (*\textcolor[HTML]{0000AA}{git switch -c fix-title}*) 150 | Switched to a new branch 'fix-title' 151 | \end{lstlisting} 152 | 153 | Modify the \cmd{moon.html} according to this diff instructions: 154 | \begin{lstlisting} 155 | (*\textcolor[HTML]{18B2B2}{@@ -7,7 +7,8 @@}*) 156 | font-family: Monospace; 157 | (*\textcolor[HTML]{AA0000}{-}*) (*\textcolor[HTML]{AA0000}{background-color: \#f0f0f0; }*) 158 | (*\textcolor[HTML]{AA0000}{-}*) (*\textcolor[HTML]{AA0000}{color: black;}*) 159 | (*\textcolor[HTML]{00AA00}{+}*) (*\textcolor[HTML]{00AA00}{background-color: black;}*) 160 | (*\textcolor[HTML]{00AA00}{+}*) (*\textcolor[HTML]{00AA00}{color: white;}*) 161 | margin: 0px; 162 | \end{lstlisting} 163 | \end{frame} 164 | 165 | \subsection{Prepare for rebase exercise} 166 | \begin{frame}[fragile] 167 | \subslidetitle 168 | Staging of all modification can be done with \cmd{-a}: 169 | \begin{lstlisting} 170 | (*\textcolor[HTML]{18B2B2}{(fix-title)}*) $ (*\textcolor[HTML]{0000AA}{git commit -a -m "change title background color"}*) 171 | [fix-title 95cb48c] change title background color 172 | 1 file changed, 2 insertions(+), 2 deletions(-) 173 | \end{lstlisting} 174 | 175 | \end{frame} 176 | 177 | \subsection{Display difference between branches} 178 | \begin{frame}[fragile] 179 | \subslidetitle 180 | 181 | As git has the complete history locally, we can easily display changes between branches: 182 | 183 | \begin{lstlisting} 184 | (*\textcolor[HTML]{18B2B2}{(fix-title)}*) $ (*\textcolor[HTML]{0000AA}{git diff master}*) 185 | diff --git a/moon.html b/moon.html 186 | index 145cfff..ae7bc15 100644 187 | --- a/moon.html 188 | +++ b/moon.html 189 | (*\textcolor[HTML]{18B2B2}{@@ -7,7 +7,8 @@}*) 190 |