Working with GIT

Been a SVN user when I started building serious projects. SVN is a centralized source control management software available for most platforms. It works fine for me for several months of work. It just works!

However, there comes a time when I need to bring source codes from one location to another and modifies code at different places where the central repository is not available. It is very cumbersome for me to transfer files from one location to another, then update the central repository afterwards. Tracking modified files becomes difficult so I need to copy the whole working copy and apply changes to the central repo.

I tried branching and merging but it is somehow very slow and I can make it work. The tutorial I followed does not just work for me. Committing and updating is very slow since it needs to connect to the central server via LAN. And the worst user experience is the slow Tortoise SVN cache that hangs up my Windows machine at the office during update/commit.

Since most of our projects are powered by Zend Framework, SVN update/commit/query becomes so slow especially if we update/commit from the project root.


Finally I tried GIT.

Git is a free & open source, distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

Indeed it was fast! This is the way I use it together with the most commonly used commands.

git init – To initialize the current directory to create a git repository.

git add . – Don’t forget the dot. It put the current working directory into staging area (index), before it is committed.

git commit -m “commit message” – To commit to the repository. It gets the file from the staging area, that’s why you need to use git add first before git commit.

gitk – To view the history using graphical interface.

git branch – To display branches.

git branch branch_name – To create a new branch.

git checkout branch_name – To checkout the selected branch to the working directory.

git merge branch_name – To merge the selected branch name to the currently checked-out branch.

git clone /path/to/source – To clone a git repository copying all its history and logs including of course the source codes.

git pull /path/to/source branch_name – To pull the changes made from the source and merge it automatically to you current branch.

git remote rm origin – To remove the remote origin from a git clone repository. This is usually done to remove a annoying message “You blah blah blah is ahead of xx commits from blah blah blah”.

Common Workflow

Being addicted sometimes to coding, I need to code in the office and at home, so here is the usual workflow using three git repository. One for the office, one at home and one on my USB flash drive.

First, after the hard work in the office, I commit all changes to the GIT repo at once. Next, I put the flash drive, go to another clone repo and issue git pull to pull the changes on my office source codes. Lastly, when I got home, I till pull the changes from the flash drive into the home repository.

When I have modified something at home, I will just do the reverse procedure.

Leave a reply

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