4.2.2. Getting Started with Git

4.2.2.1. Installing Git

You need a Git client on your PC to use Git.

On Ubuntu systems, the best way is to get Git is:

sudo apt install git-all

On windows, follow steps at https://gitforwindows.org/

Read more in details in Git Book –> Installing Git?

4.2.2.2. Setting up your username

Once you have installed Git, you need to tell Git your user name and email ID.

The command to do that is:

git config --global user.name "John Doe"

git config --global user.email johndoe@example.com

Just replace John Doe, johndoe@example.com with your real names and user id.

4.2.2.3. Your first Git Managed work

Let’s try to put our work under the control of Git.

Assuming you have stored some of your work in /Users/c6h6/data/mywork. For the sake of this book, I have ./mynotes.md and ./mywork.docx in that folder.

  1. Change your working directory to that directory in your shell / terminal:

    cd /Users/c6h6/data/mywork
    
  2. Initialize an empty Git repository there.

    git init
    

    Git would create an empty repository there and print a message like this:

    $ git init Initialized empty Git repository in
    /Users/c6h6/data/mywork/.git/
    

    A simple definition of repository is that it tracks and manages all your files and changes. Every new project must have a new repository

  3. Start the GIT GUI:

    git gui
    

    Git GUI Dialog box looks like this:

    GIT GUI Dialog box

    The dialog box has these parts:

    • 1: Un-staged / Modified files

      These are the files that have modifications. Since this an an empty repository, all changes are files are listed as modified / with changes.

    • 2: The staged files.

      These are the files or changes that we want to track.

      Select files in Un-staged Changes area and then press ^ + T or Meta + T to track them.

      The files and changes that are staged, will get tracked and stored inside the repository.

    • 3: The changes box.

      You will see changes and modifications in this box.

      You can select lines in this box to individually stage / un-stage.

    • 4: Message dialogue box.

      Give a meaningful message regarding this change, something that would make sense not only now, but a long time for now.

      Please see Commit Messages / Change Messages.

    • 5: User Commands.

      After you have selected your changes in 2, reviewed them in 3, drafted a good comment in 4, press Commit to record your changes.

      Commit means save your changes in the repository.

That’s it. Now your changes are stored in the repository. After you make new modifications, you can use git gui again to record new changes.