jmeosbn

Resources for Using Git

Here’s some basic resources to get started pushing code to github.

Note: As well as computer source code, git is useful for tracking changes to anything that can be represented as plain text, e.g. German Law.

The simplest use of git is to create the repo locally, stored in the same folder as the source (known as the working tree) and named .git.

To initialise a new git repo, simply run git-init.

$ cd my-project
$ git init
Initialized empty Git repository in my-project/.git/

Add any new or changed files you want to track, then commit those changes to the repo.

$ echo About My-Project > README.md
$ git add . # add all files recursively
$ git commit -m 'First Commit'
[master (root-commit) cdab15f] First Commit
 1 file changed, 1 insertion(+)
 create mode 100644 README.md

View recent commits using git log.

$ git log
commit cdab15f2036b0b8b1c8fbfceab6357c8e56a0d5f
Author: Jamie Osborne <jmeosbn@your-email.com>
Date:   Sat Sep 29 23:30:20 2012 +0100

    First Commit

documentation

Git itself can be installed from git-scm.com if your OS doesn’t already include it. The same site also hosts a copy of the documentation, as well as the Pro Git book which is a great place to start learning git. Pro Git is also available as a commercially printed book from Apress, and as a free ePub, mobi, or PDF download.

If you don’t fancy reading an entire book, then this Git Tutorial gets straight to the point for those already familiar with the concepts of version control. There’s minimal explanatory text, but full command examples for most operations; making it a useful resource for commands you use rarely and need to quickly relearn.

graphical interfaces

While it’s good to know how to use git from the command line, it’s worth getting a GUI for easier building of commits etc. (you could also integrate it with your favourite editor and diff viewer)

Github offers their own Mac and Windows GUI clients, which have the advantage of closer integration with some of github’s features, such as organisations and the “Clone in Windows/Mac” button found on each repo on github.

GitHub for Mac

They do lack some more advanced features though so I mostly prefer GitX on the Mac, though plenty more GUIs exist on various platforms.

GitX

other info

Btw, if you just want to share some code snippets somewhere while maintaining versioning etc., then check out gists, a feature of github.