git

Git is a distributed version control system written by Linus Torvalds for the Linux kernel.

# tell git your name and email for use in logs and patches
git config --global user.name "Fred Foobar"
git config --global user.email fred@example.com

# add remote origin
git remote add origin ssh://user@example.com/home/user/repo.git

To tell git to ignore certain files, put glob patterns in one of the following places:

  • .gitignore file in one of the parent directories that contain files to be ignored (usually the top-level project dir). This file should be used if ignore patterns should be distributed to other repos with clone.
  • $GIT_DIR/info/exclude file for ignore patterns that are specific to this particular repo.
  • file specified by core.excludesfile directive in ~/.gitconfig for patterns that should apply to all user's repos.

Git's rm --cached does not behave like SVN's rm --keep-local. The difference is that when other users of the same repo update their working copies, git will remove the files from their filesystem, while svn will not touch the newly untracked files.

Not-so-everyday Git commands

# Unstage files after they have been added to the index by mistake
git rm --cached junk.txt bogus.doc

# Show a diff between staging area (the index) and HEAD
git diff --cached

# Discard unstaged changes from a file
git checkout frotz.py

# Display log with files changed in each commit
git log --name-status

# Create archive of files from a tree
git archive --format=zip --prefix=my-plugin/ HEAD > my-plugin-0.1.zip

# Delete all commits since abc1d
git reset abc1d

# To create a bare repo from an existing non-bare one, do
git clone --bare repo repo.git

Git-SVN

# to commit changes to an SVN repo, run rebase to resync the master
# branch to the repo
git svn rebase

# then push the commit to SVN
git svn dcommit

Github

# overwrite remote master with local old_master
git push -f origin design_contest:master
git branch -f master design_contest