Skip to content


git

Presented by Ryan Curtin on February 24, 2010
Located in CoC 52

This presentation was given as an interactive demo, and this transcription does not effectively cover everything mentioned there.

1. Overview:

git is a free and open source, distributed version control system designed to
handle everything from small to very large projects with speed and efficiency.
It was originally designed for Linux kernel development, but is now used on all
sorts of projects. It is very different from conventional version control
systems like cvs or svn, and this presentation will explain the differences, as
well as give a tutorial on how to use git to its full potential. Topics that
will be covered will include basic usage of git, git emulation of cvs servers,
integration with Eclipse, and more advanced use of git.

2. Basic git commands

  • $ git init .

    create a git repository in the current directory

  • $ git add .

    add files to repository (before commit)

  • $ git commit [-a]

    commit files; -a flag specifies to include all modified files

  • $ git log

    get the log of a particular file (if specified)

  • $ git diff [--stat --summary -p]

    get diffs of files; given options increase output

  • $ git show

    get information on most recent revision set

  • $ git show $revision

    get information on given revision (e.g. HEAD)

It was discovered that the –color option is applicable to all of these commands, which could be useful if you are a Gentoo ricer. It is also important to note that ‘git commit’ will only commit files which you have told it to; when you modify a file, you have to run ‘git add $modified_file’ so that it gets checked in. The ‘-a’ flag to ‘git commit’ will automatically add all modified files.

For revision arguments, you can add modifiers to the end. For instance, HEAD^ refers to the revision before head, and HEAD^^ refers to the revision before that, and so on. There are more shortcuts, that is just one useful one.

3. Branching projects

One of the things git is known for is how easy it is to branch projects. Here is a list of commands useful for related tasks:

  • git branch

    list branches currently available (‘*’ next to currently used branch)

  • git branch $name

    create a branch with name $name

  • git checkout $name

    switch working environment to branch $name

The ‘git checkout’ command will update all of the files in your project to the newly selected branch. Once you have two divergent branches, you can merge back together with

git merge $branchname

which will merge $branchname into the current working branch.

Once you are done with a branch, you can delete it with

git branch -d $name
git branch -D $name

where the ‘-D’ option will not prompt you if the branch has not yet been merged back in.

Now, suppose you are using ‘git show HEAD^’ right after a merge, which gives you the history of the last revision… but only in the main branch. You can do ‘git show HEAD^2′ to show the other parent revision. The ‘gitk’ program provides a neat interface for looking at branching and merging tree hierarchies.

4. Cloning repositories

Most projects that use git do not use a strictly peer-to-peer distributed model but instead have one main repository that contains the most up-to-date code. You will see commands like

git clone $repositorylocation

which will get the most up to date version of that repository (similar to ‘svn checkout $repolocation’). Once you have cloned and made modifications locally, you can push them back to the origin with

git push origin

but only if you have write permissions to that repository. If you do not, someone who does will have to pull with

git pull $remoterepolocation

A long interactive tutorial was given on how to set up environments like this.

Visualization Software

There are many programs that make viewing git trees neat.

  • $ git instaweb
  • gitweb
  • gitk
  • gource
  • and so on…

See this neat video of gource in action:

Posted in Articles, Meetings.

« »