A little bit of git (a short github tutorial)

Posted by

I generate loads of code, and back up very little, so an easy to use versioning system like github seems like a no-brainer.

Setting up a repo is a little tricky if there are some things you don’t want to track (and there almost always will be). Getting the account open is fairly easy — so i’m not going to cover that here.

The official create-a-repo tutorial is fairly good, so i’m just going to add a few points where I found things a little tricky.

To begin, select the ‘Repositories’ tab, and hit the green ‘New’ button.

Screen Shot 2013-04-21 at 8.09.56 PM

My first hint is: DO NOT initialise the repo with a README file.  This will create problems later.  If you make this mistake, follow these instructions to delete the repo and start again.

Screen Shot 2013-04-21 at 8.11.16 PM

My second hint is to include a .gitignore file. To do this, before starting to add files to the index, you’ll want to create a .gitignore file.

$ cd newRepo
$ touch .gitignore
$ vi .gitignore

I wanted to exclude data (*.RData), and picture (*.pdf and *.png) files, so i added these. My .gitignore file looks like this:

Screen Shot 2013-04-21 at 8.30.05 PM

Next, follow the steps listed on the site to finalise the repo — adding the README etc.

touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/ricardianambivalence/newRepo.git
git push -u origin master

You can now proceed to git add files (git add file.r) and folders (git add ./misc/) and commit them as above — comfortable in the knowledge that the files you do not wish to have tracked are left untracked (this is particularly relevant where you are git adding folders).