basics_handouts.tex 5.04 KB
Newer Older
1 2
\documentclass{article}

3 4
\usepackage[hidelinks]{hyperref}

5
\providecommand{\handoutsTitle}{Git Basics}
6

7 8 9 10
\usepackage{multicol}
\usepackage{enumitem}
\usepackage{xcolor}
\usepackage{graphicx}
11
\usepackage{handouts}
12

13
\input{../shared/shared}
14

15 16


17 18
\begin{document}
\makeHeader
19

20 21
\subsubsection*{Connect to the education server}

Mihai's avatar
Mihai committed
22 23
Open \url{http://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html} in
your browser. It may be faster to google for putty.
24
\medskip
25

Mihai's avatar
Mihai committed
26 27 28
Download and run \href{https://the.earth.li/~sgtatham/putty/latest/w32/putty.exe}{\textbf{putty.exe}},
the standalone executable and not the installer (Alternative binary files,
the SSH and Telnet client itself).
29 30 31 32 33
\medskip

Introduce the education server IP address \textbf{145.88.35.11} as destination.
\medskip

Mihai's avatar
Mihai committed
34 35 36
Make sure that the \textbf{port number} is set to \textbf{22} and that
\textbf{SSH} is selected as \textbf{connection type} and press
``\textbf{Open}'' to start the connection.
37 38 39 40 41 42 43 44 45 46 47
\medskip

Press ``Yes'' if the security alert pops up.
\medskip

Introduce your provided \textbf{username} and press enter.
\medskip

Introduce your provided \textbf{password} and press enter.
\medskip

48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
\section{General questions}
\begin{enumerate}
  \item How can you check your local git repository state?
  \vspace{-0.2cm}
  \begin{multicols}{3}
  \begin{enumerate}[label=(\alph*)]
    \item git state
    \item git repository
    \item git commit
    \item git status
    \item git show
    \item git log
  \end{enumerate}
  \end{multicols}
  \vspace{-0.3cm}

  \item What command is used to stage a file?
  \vspace{-0.2cm}
  \begin{multicols}{3}
  \begin{enumerate}[label=(\alph*)]
    \item git stage
    \item git checkout
    \item git add
    \item git status
    \item git diff
    \item git log
  \end{enumerate}
  \end{multicols}
  \vspace{-0.3cm}

  \item How do you tell git what files to ignore?
  \vspace{-0.2cm}
  \begin{multicols}{2}
  \begin{enumerate}[label=(\alph*)]
    \item git ignore \{file-name\}
    \item add the file paths to a file named ``.gitignore''
    \item it is not possible
    \item git not track \{file-name\}
  \end{enumerate}
  \end{multicols}
  \vspace{-0.3cm}

  \item The \gitcmd\ \cmd{commit}\ command:
  \vspace{-0.2cm}
  \begin{multicols}{2}
  \begin{enumerate}[label=(\alph*)]
    \item stages all the modified files
    \item saves the staged files changes into the repository ``database''
    \item retrieves old files into the working directory
    \item shows a repository history and lets the user pick what commits to
    discard
  \end{enumerate}
  \end{multicols}
  \vspace{-0.3cm}

  \item A file is brought into the modified state when:
  \vspace{-0.2cm}
  \begin{multicols}{2}
  \begin{enumerate}
Mihai's avatar
Mihai committed
107 108
    \item[[ ]] it is staged
    \item[[ ]] it has been edited by the user
109 110 111 112 113 114 115 116 117
    \item[[ ]] the user checks out a previous version of it
    \item[[ ]] the file is committed
  \end{enumerate}
  \end{multicols}
  \vspace{-0.3cm}

\end{enumerate}

\section{Practical exercises}
118 119
\subsubsection*{Local configuration}
First, let Git know what your name and e-mail address is:
Mihai's avatar
Mihai committed
120 121 122 123 124
\medskip

\prompt\ \gitcmd\ \cmd{config} \cmdopt{--global user.name "Your Name"}\\
\prompt\ \gitcmd\ \cmd{config} \cmdopt{--global user.email "your@email.address"}\\
\prompt\ \cmd{cat} $\sim$\cmdopt{/.gitconfig}
125 126
\bigskip

127
\subsubsection*{Create a repository}
Mihai's avatar
Mihai committed
128 129
First, create an empty directory inside your home directory and use
``\gitcmd\ \cmd{init}'' in that
130
newly-created directory to make a new repository.
131
\begin{itemize}
132
  \item \emph{Hint:} Use a short and descriptive name for the directory.
133 134 135 136 137
  \item \emph{Question:} How can you see that you are working in a Git
    repository?
\end{itemize}
\bigskip

138
Check the status of your repository.
139

140
\subsubsection*{Your first commit}
141
Create a new file named ``README'' (with an editor, or by using the
Mihai's avatar
Mihai committed
142
``\cmd{touch}'' command).
143 144 145
\begin{itemize}
  \item \emph{Question:} What is the status of this new file?
\end{itemize}
Mihai's avatar
Mihai committed
146
\medskip
147

Mihai's avatar
Mihai committed
148
Stage this file for the next commit using ``\gitcmd\ \cmd{add}''.
149 150 151
\begin{itemize}
  \item \emph{Question:} What is the status of this file now?
\end{itemize}
Mihai's avatar
Mihai committed
152
\medskip
153 154 155 156 157 158

Commit your changes.
\begin{itemize}
  \item \emph{Question:} What happened to the status?
\end{itemize}

159
\subsubsection*{Manipulation in the staging area}
Mihai's avatar
Mihai committed
160 161
Edit your file. Check the repository status.
\medskip
162

Mihai's avatar
Mihai committed
163 164
Stage your modified file. Check the repository status.
\medskip
165

Mihai's avatar
Mihai committed
166 167 168 169 170 171 172
Now remove the file from the staging area. Check the repository status.
\medskip

Discard the changes performed to the file. Check the repository status.
\medskip

Edit again the file, stage it, and commit.
Mihai's avatar
Mihai committed
173

174
\subsubsection*{Working with versions}
Mihai's avatar
Mihai committed
175
Edit your file again and commit one more time.
176 177
\bigskip

Mihai's avatar
Mihai committed
178 179
Now you change your mind and you want to restore the version stored in the
previous commit.
180
\begin{itemize}
Mihai's avatar
Mihai committed
181
  \item \emph{Hint:} Use ``\gitcmd\ \cmd{log}'' to see a list of all your
182 183 184 185 186 187 188 189 190 191 192
    versions.
\end{itemize}
\bigskip

Edit your file again and check the differences with your last commit.
\begin{itemize}
  \item \emph{Question:} What is the difference with your first commit?
\end{itemize}
\bigskip

Make a file that you do not want to track.
193

194
\end{document}