Fri, 25 Dec 2009 14:07:00 GMT

Fear of Committing

When I worked at my last company we used CVS. The central repository was holy and no one could commit changes until they had been reviewed. This led to a fear of committing. What that means is that developers would develop entire features without version control as a backup and a way to undo mistakes. If you went down one path and then decided it wasn't a good idea, you had to manually back out your changes. Also, with such large change sets, developers were almost certain to have conflicting changes. That meant merges were necessary, which could lead to more errors.

Not too long ago, I went to a talk about Git. Git is very different from CVS and even its successor Subversion. Git is distributed. What that means is that everybody has their own copy of the repository. If you want to commit you can. You no longer need to fear committing to the repository because you own it. That means you can commit more often. Git also tracks your history and keeps it intact between repositories. So if you've committed 50 times and another person pulls from your repository, they get all 50 commits. Compare that with CVS or Subversion, where everything is committed as one big change and it will become apparent why Git is much better at handling merges.

A lot of people will tell you Git is fast and Git is distributed. However, those answers are vague and don't describe why it is worth abandoning what you currently have. I think better selling points would be that Git allows developers to use their version control and makes merging the job of the version control rather than the developer. Those are what sold me.

Mon, 31 Aug 2009 15:30:00 GMT

Setting Up a Repository on GitHub

GitHub offers free open source project repository hosting using the git protocol. Git is specifically designed for distributed development of software.

Creating the Repository
To create repositories on GitHub, you'll need to create an account. Once you have an account you can go to your GitHub homepage and click the link to create a new repository. Fill in the name of your project and optionally, a description and project URL. Now you have a repository.

Setting Up Shared Keys
Git connects much like ssh and uses shared keys to confirm the remotely connected computer is who they say they are. For your local git to connect to GitHub it is necessary to generate a shared key and tell GitHub what it is. To generate you own shared key, follow the instructions below:
cd ~/.ssh/
ssh-keygen -t dsa
You can hit enter through all of the prompts. You will now have two files: id_dsa is your private key and id_dsa.pub is your public key. The contents of id_dsa.pub is what GitHub need to know. On your GitHub account page there is a link to add a public key. Click that and copy the contents of id_dsa.pub into the key field and add a name to designate what computer the connection will come from. Then click the add key button. You can now connect to GitHub.

Setting Up Git
You will need to tell git your user name and email so that it can appropriately attribute your code contributions to the repository. You can do this with these commands, filling in your own information where necessary:
git config --global user.name "My Name"
git config --global user.email "MyEmail@SomeHost.com"
Note: This has set the settings globally. It is possible to set this up per project.

Commiting to the Repository
Now you need to go to the root directory of your project. If you don't have one yet you should create it. Then you can use the following commands to commit your initial project to GitHub, replacing with your GitHub username and with your repository project name on GitHub:
git init
git add --all #only do this if you have files already
git commit -m 'first commit'
git remote add origin git@github.com:/.git
git push origin master
You have officially set up your local repository and set the master to your GitHub repository.

Working with Git
From now on you can commit to your local repository with the following command:
git commit -m "A message explaining what you did"
Then, to push it to GitHub use the following command:
git push