I have been meaning to do a post on git for a while, hoping to write some gigantic treatise on how it’s such a good thing. Rather, figure I would take little chunks and blog about them. Today, I did something simple. I set up a master git repository on my web server. The benefit here is that it’s a common place with a well-known name (primordia.com) that’s available everywhere.
Previously, I had synchronized code using git between my desktop and laptop, but neither machine is an ideal master repository because:
- My laptop often has the firewall enabled
- My desktop goes to sleep often
- Both machines use DHCP and every now and then the IP changes and I don’t want to bother with static IP’s
So, my web server has shell access. I created a new user, created a new master repository, and synchronized my laptop and desktop to this repository. I imagine some of you have had experience with git and some haven’t. For those of you with no experience, git is a version control system just like CVS, Subversion, Perforce, et al.
What’s unique about git is that it’s fast, easy to use, and works on a distributed model so powerful it’s silly. The git website has this to say:
Git is aÂ free & open source, distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
Every Git clone is a full-fledged repository with complete history and full revision tracking capabilities, not dependent on network access or a central server.Branching and merging are fast and easy to do.
So, what that says is that when you create a repository from scratch, or you clone it from some remote repository (another one of your machines or a central server), the repository you create is a full repository and can serve as a master for other-sub-repositories.
Also, branching with git isÂ ridiculouslyÂ fast and easy. You can clone your entire tree instantly and start working on little experiments. Files are identified in a hidden database and all files are hashed. Hashes are compared for various operations and this makes git very fast. As far as I know, you don’t check in files, you checkin file contents.
I have my bash prompt setup so that when I’m in a branch, it shows up in my prompt. Say I have a git repot in ~/src.projects. When I’m working in the “master” branch, my prompt looks Â like this:
disven: ~/src.projects (master) $
If I create a new branch, say for some experiments, I execute these commands:
git stash assumes I want to save away changes I made to master without checking them in and I want experimental to be created from a clean master branch. Notice creating a branch and switching to it are trivial. If I want to forget about my changes, I just do this:
disven: ~/src.projectsÂ (experimental) $ git checkout master
Switched to branch ‘master’
disven: ~/src.projectsÂ (master) $ git branch -D experimental
Deleted branch experimental (was 729d6b3).