Nick Kewney

Software Architect & Product Builder

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 git@github.com:username/repo.git

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

Deleting

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

Cloning

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

$ git clone http://github.com/user/repo.git$ 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.

Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn
Share on whatsapp
WhatsApp

Leave a Reply

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