Use Git DVCS to manage your project versioning on local host

I wrote a post before: Introduce to the version control system. I have used SVN and Git with some free remote VCS host like Google Code or Github to manage the versioning of my projects. For a time of using these two VCS, I decided to choose Git as my main tool. Today, I will tell you the story how I use it in my work.

Why Git, not SVN?

Both Git and SVN have their own pros and conds. In my subjective point of view, Git have plus points in these things:

  • Git use only one folder called .git in the root of you working copy when SVN create a .svn sub folders in each sub folder of your working copy. The SVN annoys me a lot when creating so many hidden stuffs like that.
  • When using Git, you can push your code to any remote repositories. If you use SVN, you have to switch the repo before commiting to it.
  • Almost operations are did locally when using Git, which saves a lot of time when merging, committing, or reverting.
  • Git have a more efficient algorithm in storing data.

You, and some others, can say that SVN have it own exelent things. That is not wrong, and this post does not tent to specify which is better as well. I wrote this post for those who loves DVCS and want to use Git with there work.Before reading more, be sure that you can use Git at a basic level and have it in you machine. Otherwise, take a look at one of Git tutorials like Git Pro Book or community-edited Git book.

Create a normal repository

Create a normal repository is so simple with Git.

$> cd ~/your_pj
$> git init

After doing this, you have a working copy named your_pj and ready for version control.

Create a local “remote” repo to push to

One of the advantages of using a VCS is you can recover you work when needed. By default, the .git folder is in you own working folder. So what can you do if you delete it by accident? – Nothing. That’s why you need a remote repo.

There are many free service to host you Git repository on the internet, but most of them force you open your source code when using. Creating “remote” repo in some trusted location like your flash disk or a portable hard drive can help you use Git and keep your code from the public.

In my example, I use a flash dish labeled TOP-SECRET to store my backup repo. I use Ubuntu, so my device folder will be in /media/TOP-SECRET. After change to this directory, I used git init with a addition option to create the back up repo.

$>git init --bare your_pj_remote

Add the “remote” repo to your active one

The last thing to do is register the “remote” repository to your working copy and push the data when you want.

$>cd ~/your_pj
$>git remote add remote-repo /media/TOP-SECRET/your_pj_remote

If you want to back up your data, mount the deive and use the normal push command

$>cd ~/your_pj
$>git push remote-repo branch_name


Now, you have had your own VCS on your local. As I tell before, using a VCS will help you a lot in coding and managing your project. I hope you like Git and use it as a good utility.

Leave a Reply

Your email address will not be published. Required fields are marked *