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 is your public key. The contents of 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 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 "My Name"
git config --global ""
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 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