Getting started with github

I’ve just started using git/github and have summarised below (for my own reference) a few of the commonly used git commands. I haven’t included setting up your git client as this is well documented on github’s help portal.

Setting up a git repository for an existing project

To initialise the git repository in the current directory

$ git init

Create a new file named README

$ touch README

Add README file to the repository

$ git add README

Add all files in the directory to the repository

$ git add *

Commit to your local repository

$ git commit -m 'first commit'

Commiting changes locally

Summarise changes since your last commit

$ git diff

Commit your changes to your local git repository

$ git commit -a -m "whatever"

or to discard the changes to your local git repository

git checkout -f

Commiting to github (First time)

Add the remote origin to the local git repository. Do this once per repository.

$ git remote add origin

Commiting to github (Subsequent Commits)

Send your commit to GitHub

$ git push origin master

New files to add?

Add any new files since your last update

$ git add *

Getting changes from your remote repository

To update any changed files from the server to your local repository, if you are working from more than one machine, for example

$ git pull


To delete a local branch

$ git branch -d 2012.1-stable

To delete a remote branch

$ git push origin :branch

Checking out a branch

To check out a branch

$ git checkout branch


Checking out a project when you don’t have a local copy

$ git clone$ git checkout -b 2012.1-stable origin/2012.1-stable 

Two great sites are Git – SVN Crash Course or an alternative and github help resourses. I’m using Git for Windows.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.