basics_handouts.tex 4.82 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
Download and run \href{https://the.earth.li/~sgtatham/putty/latest/w32/putty.exe}{\textbf{putty.exe}.
(Alternative binary files, the SSH and Telnet client itself)}.
28 29 30 31 32
\medskip

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

Mihai's avatar
Mihai committed
33 34 35
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.
36 37 38 39 40 41 42 43 44 45 46
\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

47 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
\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
106 107
    \item[[ ]] it is staged
    \item[[ ]] it has been edited by the user
108 109 110 111 112 113 114 115 116
    \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}
117 118
\subsubsection*{Local configuration}
First, let Git know what your name and e-mail address is:
Mihai's avatar
Mihai committed
119 120 121 122 123
\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}
124 125
\bigskip

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

137
Check the status of your repository.
138 139
\bigskip

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 146 147
\begin{itemize}
  \item \emph{Question:} What is the status of this new file?
\end{itemize}
\bigskip

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

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

160
\subsubsection*{Manipulation in the staging area}
161 162 163 164 165 166
Edit your file and stage it.
\bigskip

Now remove the file from the staging area.
\bigskip

Mihai's avatar
Mihai committed
167 168 169
Stage the file and commit.
\bigskip

170
\subsubsection*{Working with versions}
Mihai's avatar
Mihai committed
171
Edit your file again and commit it one more time.
172 173
\bigskip

Mihai's avatar
Mihai committed
174 175
Now you change your mind and you want to restore the version stored in the
previous commit.
176
\begin{itemize}
Mihai's avatar
Mihai committed
177
  \item \emph{Hint:} Use ``\gitcmd\ \cmd{log}'' to see a list of all your
178 179 180 181 182 183 184 185 186 187 188
    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.
189

190
\end{document}