From BarikWiki
Jump to: navigation, search


If I had to summarize git, it would be that it is the version control system that sucks the least. It still has a million different command-line options, most of which are unintuitive to say the least.

  • For integrating with Emacs, use Magit.

Configuration File

  • The global .gitconfig is found under C:/Users/tbarik in Windows. But you can easily edit this using git config --global --edit.
  • If you want to set up your own server through SSH, use Gitolite.
  • GitHub. GitHub Help.
  • Git, the software, with Windows builds.
  • Pro Git is a free reference.
  • Show configuration in git with git config --list.
  • Git Reference
  • Aha! Moments When Learning Git
  • Want to see all the scary options? git help --all (found through git help help).
  • Amazingly, git lets you rewrite history. You can reorder history so that it makes for sense, squash several commits into one commit, or break one commit into multiple commits.
  • .gitignore when it applies to everyone; otherwise, stuff it in .git/info/exclude, which is not propagated during clone operations.

Useful Commands

  • git init, to create the repository in the first place.
  • git commit, to commit your changes. Don't forget that you can use -m multiple times for each paragraph.
  • git clone, to fork a repository.
  • git add, to add a file. If you added (staged) a file by accident, you can unstage it with git reset HEAD <file>. (git status also tells you this command.)
  • git log, which has its own multitude of options, such as git log --follow filename. git log --stat is also useful.
  • Unlike some other version control systems, git can keep track of files even after rename.
  • git push
  • git status, shows how Git sees your working tree and index.
  • git rm to remove a file, and git mv to move one. Don't use the shell's version of these!

When you're in an emacsclient editing buffer (for example, when committing), you can use C-x # ((server-edit)) to easily close it.

Git Config

What a pain.

  • DOS/UNIX text file conversion can sometimes cause problems: warning: LF will be replaced by CRLF.. To stop this from happening, set core.autocrlf = false with git config core.autocrlf false.


A branch is the fundamental means of launching a separate line of development within a software project.

  • Branch names allow for hierarchical searching: bug/pr-1023 and bug/pr-17 can be obtained with git show-branch "bug/*".
  • Think of branching as "save as", and git branch will list all branches.
  • To see all branches, you can do git branch -a. If you want to change where a remote location points to, you can use git remote set-url.
  • git branch foo will make a branch called foo off the HEAD of your current branch. It does not change your working directory to use the new branch.
  • To start working on a different branch, issue the git checkout command.
  • Deleting a branch is also easy: git branch -d bug/pr-3, but you can only delete a branch if the current branch contains those commits. You can use -D to override this.


I have a merge conflict! Now what do I do? When doing a git pull you might get a message such as:

Please, commit your changes or stash them before you can merge.

You can list your stashes with git stash list. You can drop the top stash with git stash drop. See the Git Community Book.

  • Use git merge to merge.
  • Being able to do a three-way merge is really, really important. This can be accomplished with the use of git mergetool, but you'll need an external visual merge tool.
  • You can find a list of git supported tools in the folder: C:\Program Files (x86)\Git\libexec\git-core\mergetools.
  • The best free tool for Windows is Perforce Visual Merge and Diff Tools. Git for Windows tip: Use P4Merge as mergetool is a decent guide, but it has some obsolete instructions as they apply to .gitconfig.
  • A good commercial product is Beyond Compare. See Using Beyond Compare with Version Control Systems. After some experimentation, I've ended up with bc3: it does quite a bit more than p4merge in terms of merging files.
  • To suppress the 'Hit return to the start the merge resolution tool' prompt: git config --global mergetool.prompt false.

Beyond Compare is also great for using with git difftool:

  git config --global diff.tool bc3
  git config --global difftool.bc3.path \ 
    "C:/Program Files (x86)/beyond compare 3/bcomp.exe"

GPG Support


  • git remote add origin URL_TO_GITHUB_REPO.


  • Philosophy of altering history (from Version Control with Git): realistic history, with variants fine-grained realistic history and didactic realistic history. Idealistic history.

Gitolite for Ciigar

  • Fast Gitolite instructions, specifically for ciigar.
  • To see which repositories are available using your SSH key, ssh [email protected].
  • To get the gitolite-admin repository in the first place, perform git clone [email protected]:gitolite-admin.
  • To upgrade gitolite itself, update your clone of the gitolite source and re-run gitolite setup on the server.
  • To add a repository, see here.

Low-level Operations

There's some fun low-level operations you can try, including cat-file, rev-parse, and hash-object.

  • To make a bare repository: git init --bare. By convention, bare repositories should end it .git.