Git

From Organic Design wiki
Revision as of 08:36, 20 March 2011 by Sven (talk | contribs) (.gitconfig)

Git is a distributed revision control / software code management project created by Linus Torvalds, initially for the Linux kernel development.

Git's design was inspired by BitKeeper and Monotone. Git was originally designed only as a low-level engine that others could use to write front ends such as Cogito or StGIT. However, the core Git project has since become a complete revision control system that is usable directly. Several high-profile software projects now use Git for revision control, most notably the Linux kernel, X.org Server, One Laptop per Child (OLPC) core development, and the Ruby on Rails web framework.

Git differs from systems such as CVS, or SVN in that the database is maintained beside the working filesystem on peers. Each peer is easily sync'ed to any other by using push/pull or fetch. In subversion you use three main directory structures;

  • trunk
  • branch
  • tag

In git the trunk is equivalent to HEAD, and is a sha1sum to the latest commit. Branches are used to fork development from the HEAD if for example bug fixing is required. A tag in git is just a named sha1sum commit which is effectilvely a static reference to a particular snapshot of code.

If a repository is cloned, git tracks the master which is the latest commit on the remote repository, as well as the origin/master which is the last known commit from the source sourced repository. This is updated if your remote changes are pushed back to the repository you cloned from.

We could use Git to maintain article revisions for the P2P MediaWiki Extension.

Git GUI

Git Gui is a Tcl/Tk based graphical user interface to Git. git-gui focuses on allowing users to make changes to their repository by making new commits, amending existing ones, creating branches, performing local merges, and fetching/pushing to remote repositories. Unlike gitk(1), git-gui focuses on commit generation and single file annotation, and does not show project history. It does however supply menu actions to start a gitk session from within git-gui.

Git clone

If you are cloning from some elses repository you should generally always do this on the same machine. The reason is that unless the file permissions are set accordingly you will not be able to push changes back to their version of the repository, so within a machine you can clone some elses repo, but between machines you should generally clone your own copy of a repo so that you can push and pull changes between machines. It may be that the users mask could be altered from 022 to 011, in shared repo directories but this needs testing.


<bash>
    1. Probably the first thing you want to do, clone a repository

git clone git@ssh.github.com:[user]/[project]

    1. Locally commit something

touch foo git add foo

    1. commit changes to local repository

git commit -m "test"

    1. Push changes back to git-hub

git push </bash>

Time to go back...

Reverting what you’ve done since last commit is easy.

<bash>

$ git diff .bashrc

And for svn

<bash>

$ svn diff .bashrc

The idiom of sourcecode management is “commit often”. You can always role back any number of steps at a time. Rolling back half a step is difficult though.


<bash>

$ cat <<'EOF' > ~/bin/git_revert

  1. !/bin/bash

git diff "$*"

.gitconfig

The .gitconfig file is either in /etc, or $HOME, and is configurable either directly through the git commands;

<bash>
git config --global doe@foobar.com
git config --global user.email "doe@foobar.com"
    1. Pretty colours

git config --global color.branch "auto" </bash>

Or directly by editing the file $HOME/.gitconfig.

{{{1}}}

Free GIT Servers

Github is the recognized centralized Git repository, but it is a pay site, so if you want your own free Git setup there are three ways:

  • Set up a bare Git server.
  • Install one of two free Github fork:
    • Gitolite is the up-and-comer and has a more decentralized approach
    • Gitosis has better documentation.
  • Gitolite is easier to implement and has P2P-like host features so is probably more suitable.

Links to Setting up Git Servers