Git

Git is a version control system, designed to track changes in text files, like source code. Is also distributed, unlike SVN. The de facto standard for distributed version control.

Mental Model

What if you glue together:

  • CAS: Content-addressable storage for objects
  • DAG: Directed Acyclic Graph for commits
  • Pointers: References, like tags and branches
  • Protocol: 30+ subcommands (plumbing and porcelain)

Concepts

Repository

A repository is a directory tree tracked by Git:

  • Local repository
  • Remote repository: Hosted somewhere (see also: Git Forge)

Objects

Git is a content-addressable filesystem. Great. What does that mean? It means that at the core of Git is a simple key-value data store. What this means is that you can insert any kind of content into a Git repository, for which Git will hand you back a unique key you can use later to retrieve that content.

  • blob: The content
  • tree: Maps the blobs to a structure like a filesystem
  • commit: A picture (snapshot) of your project at the time.
    • Has an id (SHA hash)
    • Points to a parent commit
    • Has metadata (author, date, message)
  • tags: Points to the same commit

References

Because using lucky-commit to rewrite all commits is insane.

  • refs/heads/*
  • refs/tags/*
  • refs/remotes/*

Packfiles

Compress files to use storage efficiently. You can run manually with git gc.

Refspec

The format of the refspec is, first, an optional +, followed by <src>:<dst>, where <src> is the pattern for references on the remote side and <dst> is where those references will be tracked locally. The + tells Git to update the reference even if it isn’t a fast-forward.

History

Linus Torvalds created to support development of Linux kernel in April and turned over maintenance to Junio Hamano on July 2005.

ReferencesLink to other things

Usage Patterns

How do I bop, twist, pull, spin, flick and shake?

TipsJust the tips

Things not in usage patterns

Colors

To add colored output to git, you can change color.ui.

[color]
ui = auto

Extending git

You can use git $command if your binary is named git-$command and is inside $PATH.

see also: StackOverflow/10978257 and execv_dashed_external

Example

git-shortstat
git log --numstat --format="" "$@" | awk '{files += 1}{ins += $1}{del += $2} END{print "total: "files" files, "ins" insertions(+) "del" deletions(-)"}'