basics_handouts.tex 4.65 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 22
\subsubsection*{Connect to the education server}

Open \url{http://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html} in your browser.
23
\medskip
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42

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)}.
\medskip

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

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.
\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

43 44 45 46 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
\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
102 103
    \item[[ ]] it is staged
    \item[[ ]] it has been edited by the user
104 105 106 107 108 109 110 111 112
    \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}
113 114 115 116 117 118 119 120 121
\subsubsection*{Local configuration}
First, let Git know what your name and e-mail address is:
\begin{lstlisting}
  $ git config --global user.name "Your Name"
  $ git config --global user.email "your@email.address"
  $ cat ~/.gitconfig
\end{lstlisting}
\bigskip

122
\subsubsection*{Create a repository}
123
First, create an empty directory inside your home directory and use ``\lstinline{git init}'' in that
124
newly-created directory to make a new repository.
125
\begin{itemize}
126
  \item \emph{Hint:} Use a short and descriptive name for the directory.
127 128 129 130 131
  \item \emph{Question:} How can you see that you are working in a Git
    repository?
\end{itemize}
\bigskip

132
Check the status of your repository.
133 134
\bigskip

135
\subsubsection*{Your first commit}
136
Create a new file named ``README'' (with an editor, or by using the
137
``\lstinline{touch}'' command).
138 139 140 141 142
\begin{itemize}
  \item \emph{Question:} What is the status of this new file?
\end{itemize}
\bigskip

143
Stage this file for the next commit using ``\lstinline{git add}''.
144 145 146 147 148 149 150 151 152 153 154
\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

155
\subsubsection*{Manipulation in the staging area}
156 157 158 159 160 161
Edit your file and stage it.
\bigskip

Now remove the file from the staging area.
\bigskip

162
\subsubsection*{Working with versions}
163 164 165 166 167
Commit your changed file.
\bigskip

Now you change your mind, and want to revert this commit.
\begin{itemize}
168
  \item \emph{Hint:} Use ``\lstinline{git log}'' to see a list of all your
169 170 171 172 173 174 175 176 177 178 179
    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.
180

181
\end{document}