Submitted by sean on Fri, 09/17/2010 - 12:55

Over the years I've used many version control systems, from sccs, rcs to svn and more recently bzr.

I'd heard of git, but was wary of the complexity. However Drupal is moving to git and I had to use it for a new project.

The good news is that there is an excellent book on line or in paper form, that is well written and easy to follow: by Scott Chacon. There are some O'Reilly books in both German and English but I've not read those yet.

GIT really is very interesting: it's worth the effort to move from CVS or SVN!

Some examples ..

Add a module
$ git add MODULENAME
$ git commit -m "added module MODULENAME" MODULENAME

$ git status

-- git log --
git log -10
git log -p -1
git log --stat  -2
git log --pretty=oneline
git log --pretty=format:"%h - %an, %ar : %s"
git log --pretty=format:"%h %s" --graph                    *
git log --pretty=format:"%h - %an, %ar : %s"  --graph
git log --pretty=oneline --since=2.weeks
git log --pretty="%h - %s" --author=boran --since="2010-09-01"
# Commits unmerged that do not refer to branch branch1
git log --no-merges origin/master ^branch1

-- Git config
git config --global
git config --global MYNAME# aliases
git config --global checkout
git config --global branch
git config --global commit
git config --global status
git config --global alias.unstage 'reset HEAD --'
git config --global alias.last 'log -1 HEAD'
# external command
git config --global alias.visual "!gitk"

--- fix the last commit ---
git commit -m 'initial commit'
git add forgotten_file
git commit --amend

-- Unstaging a Staged File: 'reset' not revert :-)
git reset HEAD testfile

-- Unmodifying a Modified File
git checkout -- testfile

-- Tags
git tag
git tag -a v1.0 -m 'SB: First version'
git show v1.0
# Tag a previous version
git tag -a v0.9 -m 'prlease alpha1' ea32e7
# Push one or all tags up to master
git push origin v1.5
git push origin --tags

-- Remotes
git remote add [shortname] [url]
git fetch [remote-name]
git push [remote-name] [branch-name]

$ git remote -v
origin  /home/XX/git/

git clone git.folder
git remote add pb git://
git fetch pb
git remote rename pb paul

git fetch origin
git push origin [branchname]
# remote sys:    git merge origin/[branchname]
# or branch too: git checkout -b [local branchname] origin/[branchname]

-- branches: create a branch with the module sitedir_migrate
git checkout -b  [branch name]  [source, e.g. origin/master]
   git branch sitedir_migrate
   git checkout sitedir_migrate
   drush dl sitedir_migrate
   git add sitedir_migrate
   git commit -m 'add module sitedir_migrate'
   git checkout master            (switch back to master)
   git branch --no-merged        (list unmerged branches)
   git status
   git merge sitedir_migrate      (fast fwd commit)
or first:
   git checkout sitedir_migrate
   git rebase master               (pull in any master changes)
   git rebase master sitedir_migrate
   **Do not rebase commits that you have pushed to a public repository.
   git mergetool                   (if conflicts)   
   git branch -d sitedir_migrate   (if branch no longer needed)

Project forking & patch submissions: see
   git request-pull origin/master myfork
   git checkout -b featureBv2 origin/master
   git merge --no-commit --squash featureB
    (change implementation)
    git commit
    git push myfork featureBv2

   git format-patch -M origin/master