Main Content Area

Getting Started with Git

Git Logo

What is Git?

Git is a revision control system that is designed to used over a distributed network and operate in a quick and efficient way. Git is open-source software, originally written by Linus Torvalds, creator of Linux.

The system was specifically designed for version control of the Linux kernel software, which is developed by multitudes of developers all over the world. Since then, it has become a widespread tool within software development.

According to wikipedia, the name git is derived from a British slang word.

git
(British Slang) an unpleasant or contemptible person.
I'm an egotistical bastard, and I name all my projects after myself. First 'Linux', now 'git'. Linus Torvalds

Why should I use it?

Once you begin using git and familiarize yourself with the system, your workflow will be supercharged with the following benefits:

  • Detailed version tracking of all of your working files
  • Restoring to an older version of your files if recent changes were problematic
  • Comparing old versus new versions to see the changes that were made over time
  • Simultaneous editing of the same files by multiple people
  • Backing up your files to a remote repository
  • Branching off the main project to try something out without damaging original code
  • Forking existing projects into new projects
  • Logging activity in the files between several team members
  • Setting up working files from a remote repository on a new computer

All these benefits come at minimal cost in terms of time, the software is relatively easy to install and use. It also takes very little time out of your workflow and works quicky and efficiently.

Git – the stupid content tracker. Git Manual Page

Getting Started

In order to get started with git, you must install the command-line client. You can download a version specific to your OS here: Git Client Downloads.

There are many options, including a few GUI clients for git. For the purposes of this article, we will be using the command-line version of the git client. The command-line provides all of git's functionality, with no inherent constraints. If you spend the time to learn the commands, you will find it is the fastest and easiest way to work with git.

Starting a new Repository

To start using git, first find the folder or project that you are interested in tracking. One easy way to do this, is to locate the folder within Finder, then open the terminal (in Applications/Utilities).

On a Mac, the Terminal App is found in the
Applications > Utilities folder.
Terminal App

Once the terminal opens, type in the following:

cd 

Open up Finder and browse to the folder you wish to track with git. Drag the desired folder's icon onto the terminal app window- this will insert the path to your folder automatically. It should look something like this:

cd /your/folder/path/will/go/here/

Hit the Enter key to execute the command. This will set the current directory in the terminal to your desired folder.

Assuming you are in the correct folder, the first step will be to initialize your git repository. This can be done by typing:

git init .

This literally tells git to initialize, at directory '.' which in command-line terms means the current directory (the one you cd'd to earlier).

Next it's a good idea to tell git which files to ignore. For example, in MacOS there are hidden files in every folder called ".DS_Store"; these store the attributes you apply to each folder. It's not a huge deal, but you will find that file in every folder of your project when you view your code repository.

To remedy these sorts of issues pre-emptively, start up the 'nano' editor:

nano .gitignore

Add the following lines to what should be currently an empty file:

 GNU nano 2.0.6                New Buffer            						

# ignores the file you are now creating
.gitignore

# ignores MacOS hidden directory attributes files
.DS_Store

# ignores Windows hidden thumbnail cache files
THUMBS.DB

# add whatever else you need git to ignore here as well 



^G Get Help  ^O WriteOut  ^R Read File ^Y Prev Page ^K Cut Text  ^C Cur Pos
^X Exit      ^J Justify   ^W Where Is  ^V Next Page ^U UnCut Text^T To Spell

You can list any additional files you want to ignore. When you are ready, save the file by pressing CTRL+X, and type in 'yes' to write the changes. If you need to make changes in the future, just run 'nano .gitignore' in this directory again and you can edit as needed.

You are now ready for your initial commit, first make git aware of all your files:

git add --all .

Then commit the changes in all those files and supply a message to describe them:

git commit -m 'initial commit'

Your local repository is now ready to be used, and you can readily keep going from here.

Typical Local Workflow

There is obviously a lot more to Git than will fit in this article, but on a basic level if you've followed the steps above, you can now track your project as you work on it.

The beauty of Git is that it records all the individual changes you make to your work locally, in a hidden folder named .git. If you want to stop tracking a project, just delete the .git folder and it will as though you have never used it. It also means that you can use all of what Git has to offer without even a internet connection, since all the changes are recorder locally.

In general you can work like this:

  1. Make some changes and edits to your code.
  2. Test them and make sure the changes you made work correctly.
  3. Tell Git to scan your files for changes.
    git add --all .
  4. Commit your changes to Git.
    git commit -m 'put a note about what you changed here'
  5. Start back at step 01.

Typical Local Workflow

There is obviously a lot more to Git than will fit in this article, but on a basic level if you've followed the steps above, you can now track your project as you work on it.

The beauty of Git is that it records all the individual changes you make to your work locally, in a hidden folder named .git. If you want to stop tracking a project, just delete the .git folder and it will as though you have never used it. It also means that you can use all of what Git has to offer without even a internet connection, since all the changes are recorder locally.

In general you can work like this:

  1. Make some changes and edits to your code.
  2. Test them and make sure the changes you made work correctly.
  3. Tell Git to scan your files for changes.
    git add --all .
  4. Commit your changes to Git.
    git commit -m 'put a note about what you changed here'
  5. Start back at step 01.