A short introduction to git
April 25th 2016
Git is a distributed version control software written by Linus Torvalds himself, the creator of the Linux kernel. The program was designed to keep track of every change that occurs in a specified directory.
Quick tip: Before diving into git, I want to point out the fact that you should be familiar with the Linux command line.
We have an accessible tutorial (with animated screenshots) that covers the command line here on Super Brackets.
If you’re on a Windows machine, you will have to download git from the website and install it - the Windows way.
On the other hand, if you're working on a Linux machine (Ubuntu), you can install the software from the terminal.
alt + t to launch the terminal and then type the following command:
sudo apt-get install git
Now you're ready to use git.
Windows users will have to locate the Git Bash application and launch it, Linux users need only the terminal.
Initialize a git repository
A git repository is a folder (or directory) that git watches for changes.
Let's create a new directory called
test, this will be our testing repository.
To navigate to the newly created folder, you will have to type:
Let's initialize git:
Congratulations, you've just created a new git repository!
Don't rush to make changes inside the folder.
We need to tell git our full name and our email address ~ these settings are mandatory.
I will place a dummy name and a random email address, you should change these settings to your real ones.
Run the following command to set your name:
git config user.name “John Doe”
To set the email address, you need to run:
git config user.email “firstname.lastname@example.org”
Making changes inside the repository - using git
Now that you've got the repository configured, you can start using git. Let’s make some changes inside the folder.
Let’s create some files:
touch file1 file2
By running the above command, you created two empty files called
One of the most useful git commands is:
Git status displays the status of the repository, you can see the files that were edited, deleted or the ones that are new.
You should see that there are two untracked files.
In order to track those files, you need to add them to the staging area:
git add file1 git add file2
If you type
git status again, you'll see that the files are now added to the staging area and ready for commit.
You can commit the changes using the
git commit -m "Commit Message" command (You set the commit message in between the quotes).
git commit -m "Created two empty files"
Congratulations, you've just created your first commit message.
If you run
git status again, you will see that there are no changes in the repository.
The updates that we commit, will not showed in
You can view your commits using the
git log command:
Now, let's delete one of those files.
That command removed the file entitled
file1 from the
If you run
git status again, you should see that
file1 is missing from the repo (obvious, right ?).
We have to update the staging area, instead of running
git add, you will have to use
git rm file1
Git status will show that the file is removed and the repo is ready for a commit.
git commit -m "Removed `file1` from the root folder"
This should wrap it up. This tutorial covered how to initialize a git repo, how to add files to the staging area, how to remove files from the staging area, how to commit changes and how to view your commit log.
If you want to learn more about git, you should search about branching, merging and creating pull requests.
Memorize the following commands because you'll be using them most of the time:
git status # Displays the current status of the repository git add # Adds the changes to the staging area git rm # Removes the trace of files from the working area git commit # Commits the changes to the repository git log # Displays all the commits
I hope you found this tutorial useful, thank you for your time.