\begin{exe} {Version Control with \textbf{git}}

   \begin{lfbox}[Making sure git is installed]
      Your system may already have \textbf{git} installed. Doing
      \verb?which git? should show you if it is already
      present. If not, while you may obtain the source and
      compile and install it, it is usually easier to install
      the appropriate pre-compiled binary packages.  Exact
      package names may vary, but one of the following should
      work depending on your distribution:
      \begin{cmd}
 $ sudo apt-get install git*  # Debian /Ubuntu
 $ sudo zypper install git*   # openSUSE
 $ sudo dnf install git*      # Fedora / RHEL 8 / CentOS 8
 $ sudo yum install git*      # RHEL 7 / CentOS 7
   \end{cmd}
      according to your particular distribution.
   \end{lfbox}

   Let's get a feel for how \textbf{git works} and how easy it
   easy to use. For now we will just make our own local
   project.
   \begin{enumerate}

      \item

      First we create a working directory and then initialize
      \textbf{git} to work with it:

      \begin{cmd}
$ mkdir git-test
$ cd git-test
$ git init
      \end{cmd}

      \item

      Initializing the project creates a \verb?.git?
      directory which will contain all the version control
      information; the main directories included in the project
      remain untouched. The initial contents of this directory
      look like:

      \begin{cmd}
$ ls -l .git
      \end{cmd}
      \begin{response}
total 40
drwxrwxr-x 2 coop coop 4096 Dec 30 13:59 branches/
-rw-rw-r-- 1 coop coop   92 Dec 30 13:59 config
-rw-rw-r-- 1 coop coop   58 Dec 30 13:59 description
-rw-rw-r-- 1 coop coop   23 Dec 30 13:59 HEAD
drwxrwxr-x 2 coop coop 4096 Dec 30 13:59 hooks/
drwxrwxr-x 2 coop coop 4096 Dec 30 13:59 info/
drwxrwxr-x 4 coop coop 4096 Dec 30 13:59 objects/
drwxrwxr-x 4 coop coop 4096 Dec 30 13:59 refs/
      \end{response}
      Later we will describe the contents of this directory and
      its subdirectories; for the most part they start out empty.

      \item

      Next we create a file and add it to the project:

      \begin{cmd}
$ echo some junk > somejunkfile
$ git add somejunkfile
      \end{cmd}

      \item

      We can see the current status of our project with:

      \begin{cmd}
$ git status
      \end{cmd}
      \begin{response}
 On branch master

 Initial commit

 Changes to be committed:
   (use "git rm --cached <file>..." to unstage)

       new file: somejunkfile

      \end{response}
      Notice it is telling us that our file is \textbf{staged}
      but not yet \textbf{committed}.

      \item
      Let's tell \textbf{git} who is responsible for this repository:


      \begin{cmd}
$ git config user.name "Another Genius"
$ git config user.email "b_genius@linux.com"
      \end{cmd}
      This must be done for each new project unless you have
      it predefined in a global configuration file.

      \item

      Now let's modify the file, and then see the history of
      differences:

      \begin{cmd}
$ echo another line >> somejunkfile
$ git diff
      \end{cmd}
      \begin{response}
diff --git a/somejunkfile b/somejunkfile
index 9638122..6023331 100644
--- a/somejunkfile
+++ b/somejunkfile
@@ -1 +1,2 @@
 some junk
+another line
      \end{response}

      \item

      To actually commit the changes to the repository we do:

      \begin{cmd}
$  git commit -m "My initial commit"
      \end{cmd}
      \begin{response}
Created initial commit eafad66: My initial commit
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 somejunkfile
      \end{response}
      If you do not specify an identifying message to
      accompany the commit with the \verb?-m? option you
      will jump into an editor to put some content in. You
      \textbf{must} do this or the commit will be
      rejected. The editor chosen will be what is set in
      your \verb? EDITOR? environment variable, which can be
      superseded with setting \verb?GIT_EDITOR?.

      \item

      You can see your history with:

      \begin{cmd}
$ git log
      \end{cmd}
      \begin{response}
commit eafad66304ebbcd6acfe69843d246de3d8f6b9cc
Author: A Genius <a_genius@linux.com>
Date:   Wed Dec 30 11:07:19 2009 -0600

    My initial commit
      \end{response}
      and you can see the information got in there. You will
      note the long hexadecimal string which is the
      \textbf{commit number}; it is a 160-bit, 40-digit
      unique identifier.  \textbf{git} cares about these
      beasts, not file names.

      \item

      You are now free to modify the already exiting file and
      add new files with \verb?git add?. But they are staged
      until you do another \verb?git commit?

      \item

      Now that was not so bad. But we have only scratched the
      surface.

   \end{enumerate}
\end{exe}


