Git is a free open source distributed version control system. Which sounds incredibly dull, until you need to revert to a prior version of your code, when it’s a godsend.

It’s software that manages your source code, by taking snap shots of it at particular points and stores them. You can view all these intervals as milestones in a timeline. This way it allows you to back track, restore code from particular points, and work in a team simultaneously.

One of the biggest advantages of using Git, is that it is a distributed system. This means everyone can have a copy of the code repository and work on it individually. Each person can push and pull to another repository should they choose to.

Through this tutorial, I’ll guide you through how to install and setup Git and the basic commands to get you started using Git quickly.


The easiest way to install git on a PC or Mac is to use the installer package. Go ahead and download the installer package from Double click on it and follow the wizard to install Git on your computer.


If you don’t want to use the command line when using Git you can always choose one of the following Git GUI clients:


Now that Git is installed, let’s configure it. Set your own name and default email address:

$ git config --global "Joe Bloggs"
$ git config --global ""


With our Git setup we’re ready to create our first Git repository. Go to your projects directory:

$ cd path/to/project

Run this following command to create a git repository:

$ git init

As you can see its incredibly simple to setup Git for a project. Whenever you need to use Git just run this command to get started.

We can now use the Git status command to check the current status of our repository:

$ git status

Status commands confirm there is nothing to commit, the current directory is clean.

We’ve initialized Git for our project but we need to register our project files for Git to track them. To add files to the project, list them out manually like so:

$ git add index.html style.css

If you prefer to have all your files in the working directory tracked, just type:

$ git add .

This will push all your files into Git’s staging area.

This is just to prepare the files ready to be committed. We have yet to actually commit this for Git to snap shot changes made to each individual file.

With the files/folders now tracked in Git we can move forward and commit our changes. Commits are are the most basic function of Git, they snapshot your changes. Every time we commit we need to supply a short summary to remind us what each commit is about:

$ git commit -m "Initial Commit"


Branching is a powerful concept in Git. If you wanted to develop new functionality but do not want to risk spoiling your project you create a branch which clones the main branch in a separate environment to safely test and develop new ideas. Once you are happy you can always merge this back into your main master branch.

$ git branch

Currently our project only has one branch as you can see from the output this is the default branch typically named master. It is prefixed with an asterisk to indicate this is the current branch we are on.

Let’s create a new branch to build some new custom features. To do this in the command line run:

$ git checkout -b new-features

We just created a new branch called ‘new-features’ and switched to this branch. If we run Git branch you’ll see this displayed:

In our new branch we’ll add in some new JavaScript files. If we do a git status, it will identify the new JavaScript files are untracked. So we’ll stage it and commit the JavaScript library:

$ git add .
$ git commit -m "JavaScript Library"

Currently these are the project files in our directory:

Now if we switch back to our master branch.

$ git checkout master

start git

If you look at our project directory, you’ll see the JavaScript folder isn’t present. This is because we had committed all this to the new-features branch. That’s the beauty of branching: whatever you commit in one branch will not be visible in other branches.

To help visualise the Git commits in a tree view we can use a visualisation tool that is bundled with Git, called gitk. In the command line run:

$ gitk

This now opens gitk in a new window. Here you can view all the commits made in the top left corner. Each commit is represented as a dot accompanied with the commit message. It also displays the name of who committed this and the date in the next columns. Below are further information regarding the specific commit, what files are committed, and the change set.

start git

You may notice this does not mention anything about the new-features branch. This is because gitk is only executed on the master branch. We can use the —all flag to display all branch commits. Close the gitk window and in the command line run:

$ gitk —all

Now we can see the commits made in all the branches including new-features.

start git

Let’s say we finished working on our new features and are happy with the final result. Let’s merge our new-features branch into the master branch.

Close gitk and in the command line run:

$ git merge new-features

start git

We just merged the new features branch into the main branch. If you look at our project files you will see the JavaScript has been merged in.

start git

There are situations where you do not wish to commit everything to your Git repository—personally I use SublimeText as my text editor, but this software generates a .sublime-project and .sublime-workspace file which I don’t need to commit. Also your operating systems may generate empty files such as .DS_Store or trash files.

In the command line if you run a git status, you will notice Git will highlight these files and specify that they aren’t tracked.

start git

To resolve this, we can use .gitignore, a !le listing all the directories and files you don’t want committed to the repository. Create a new file and name it “.gitignore” (make sure the filename has a dot preceding it). Inside this file add:

# Sublime Text generated files #

# OS generated files #

Anything prefixed with a hash will be commented out in this file. Now save the file. Run git status again, you’ll noticed both the Sublime Text generated files are no longer listed. The only file untracked is the .gitignore. Let’s add this and commit it:

$ git add .
$ git commit -m "git ignore file"

Once you hit a particular point in your development you’ll want to reference it. You’ll want to make releases, most often versioning your project. This is called tagging in Git. A tag is a static snapshot of the repository at that particular moment in time, referenced with a name. There are two types of tags. One is lightweight, a label to a pointer in your commit history; the other is the annotated tag, which contains more information including who was the original creator of this tag, date created and a short annotation message.

To assign a lightweight tag on the current revision, in the command line run:

$ git tag release-

This names our tag with the parameter of release-

To create a new annotated tag we simply add a -a flag and a -m flag to apply a short annotation:

$ git tag -a release- -m "First full public release"

To view all our tags we have in a repository we run:

$ git tag

If you would like to view more information on a particular tag, use git show with the tag parameter:

$ git show release-

This will show the full details on this particular tag, including the name of tagger, the date it was created and annotation.

Related posts

  1. IELLIOS是由歐盟資助倫敦大學細胞重建研究所研究. 採用諾貝爾生理醫學獎科技 , 透過”納米能量電流” 以最親膚與迅速導入的方式 , 利用電腦化系統去令皮膚再生 , 令皮膚組織在無創傷的情況下自然更新及收緊 . 這治療是無創無痛的 . 完成治療後亦沒有傷口 . 我們是香港第一引入IELLIOS的機構 , 醫生會根據客人不同情況去為你設計不同的組合 .在外國IELLIOS受到很多荷里活明星, 歌手以至政客的追棒 , Madonna的facialist kate somer -field就常用IELLIOS為她護理肌膚 , 令52歲的她肌膚輪廓均保持於30歲的狀態. IELLIOS的訊號技術,採用心臟起博起原理,活躍無法正常運作的心臟細胞。訊號技術可活化及修復愛損皮膚,透過傳送訊號,激活靜止的細胞。IELLIOS的訊號技術給予細胞指令,引發細胞再次生長,令肌膚重回年輕。

  2. 倩碧卓越润肤乳,全新的倩碧有油黄油.升级配方,创新修护科技,提升弹润膜力,带来内润外弹光采肌.全新倩碧天才黄油+,专注修护天然肌肤保护膜力,成就弹润膜力升级,内润外弹,卓效不凡,倩碧小黄油带来更好的滋润护肤体验!消脂針

  3. YANAGIYA 柳屋 商品一覽 找品牌 以UrCosme指數高至低排序 第1頁 YANAGIYA 柳屋 化妝品商品一覽,提供 YANAGIYA 柳屋的產品列表,以UrCosme指數高至低排列,共15件,YANAGIYA 柳屋的搜尋結果之第1頁玫瑰水

  4. I am just commenting to make you know of the amazing discovery my princess enjoyed browsing yuor web blog. She came to find a good number of issues, which included what it is like to have an excellent coaching style to let folks effortlessly master some very confusing matters. You truly surpassed our own expected results. Many thanks for distributing such valuable, trusted, explanatory as well as cool tips about your topic to Ethel.

  5. My wife and i got now happy that Raymond managed to round up his preliminary research via the ideas he made from your own web page. It is now and again perplexing just to find yourself releasing instructions that many many people could have been making money from. And we all do know we have the website owner to thank because of that. The entire explanations you’ve made, the straightforward web site navigation, the relationships you can aid to promote – it’s everything amazing, and it is letting our son in addition to the family recognize that that theme is fun, and that’s incredibly pressing. Many thanks for all!

  6. I as well as my pals have already been examining the nice helpful tips located on your website and so quickly I had an awful feeling I had not thanked the web blog owner for those strategies. All of the women came thrilled to read through all of them and have in effect pretty much been taking advantage of them. I appreciate you for indeed being so helpful as well as for deciding upon varieties of important ideas most people are really needing to understand about. My very own sincere regret for not expressing appreciation to you sooner.

Leave a Reply