From Evgeny Goldin

Jump to: navigation, search










  • apt-get:
sudo apt-get install git-core

  • Build from sources (download):
sudo apt-get install libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev
wget --no-check-certificate
tar -zxf v1.7.11.1
cd git-git-d636c48
make prefix=/usr/local all
sudo make prefix=/usr/local install

  • Build from sources (git clone):
sudo apt-get install libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev
git clone git://
cd git
git checkout v1.7.11.1
make prefix=/usr/local all
sudo make prefix=/usr/local install

Hosting Git Repository

mkdir <project>
cd    <project>
git   init
touch README.makrdown
git   add README.makrdown
git commit -m "First commit"
git remote add origin<user>/<project>.git
git push   -u origin master

git instaweb

sudo apt-get install lighttpd
git instaweb : Starts a web server on ''
git instaweb --httpd=webrick
git instaweb --stop

Git Model

Git Objects

Object Description
blob A bunch of bytes. This is often a file, but can be a symlink or pretty much anything else.
tree Refers to blobs that have the contents of files (filename, access mode, etc is all stored in the tree), and to other trees for subdirectories.
commit Refers to a tree that represents the state of the files at the time of the commit. It also refers to 0..n other commits that are its parents.
refs ".git/HEAD", ".git/refs/heads", ".git/refs/tags"
Post-it notes slapped on a node in the DAG. Where DAG only gets added to an existing nodes and cannot be mutated, the post-its can be moved around freely. They don't get stored in the history, and they aren't directly transferred between repositories. They act as sort of bookmarks: "I'm working here".
remote refs ".git/refs/remotes"
Post-it notes of a different color. The difference to normal refs is the different namespace, and the fact that remote refs are essentially controlled by the remote server.
"git fetch" updates them.
tag Both a node in the DAG and a post-it note (of yet another color). A tag points to a commit, and includes an optional message and a GPG signature.

Git References

  • "Pro Git" - Git References
  • The "HEAD" ref is special in that it actually points to another ref. It is a pointer to the currently active branch. Normal refs are actually in a namespace "heads/XXX", but you can often skip the "heads/" part.
  • .git/HEAD => .git/refs/heads/[branch name]
  • .git/refs/tags/[tag name]
  • .git/refs/remotes/[remote name]/[branch name]
    Can't be checked out like 'refs/heads', bookmarks to the last known state of remote branches.


"Plumbing" commands

Command Description
hash-object Computes object ID and optionally creates a blob from a file, can write it into object database
cat-file Provides content or type and size information for repository objects
update-index Registers file contents in the working tree to the index
write-tree Creates a tree object from the current index
read-tree Reads tree information into the index
commit-tree Creates a new commit object
update-ref Updates the object name stored in a ref safely
symbolic-ref Read and modifies symbolic refs
verify-pack Validates packed git archive files

git reflog = git log -g --oneline   : Manages reflog information, a mechanism to record when tips of branches are updated
git show master^                    : Shows various types of objects
git show tag
git show HEAD@{5}
git show HEAD@{2.months.ago}
git show master@{yesterday}
git ls-tree master^{tree}           : Lists the contents of a tree object
git ls-tree -r -t master^{tree}     : Recurses into sub-trees, shows tree entries even when going to recurse them
git ls-files -u                     : Shows information about files in the index and the working tree (unmerged)
git cat-file -t ae850bd698b2b5dfbac : Provides type and size information for repository object
git cat-file -p ae850bd698b2b5dfbac : Pretty-prints the contents of object based on its type
$git cat-file -p "master^{tree}"
100644 blob 3c1c2aa022f6a5b22e421103eb6c07472c709c89    .gitignore
100644 blob ae6b064c33d8c62105c1d07cf90537ece4bd32d2    README.txt
040000 tree c4762af6d722bf8e9d79dc0e6741caffbf334b9d    assert-maven-plugin
040000 tree 55e8650b30e002689c865e8eb15797fe86bf4a19    maven-common
$ cat .git/HEAD
ref: refs/heads/master
$ cat .git/refs/heads/master
$ git cat-file -p e9a570524b63d2a2b3a7c3325acf5b89bbeb131e
tree cfda3bf379e4f8dba8717dee55aab78aef7f4daf
author Scott Chacon  1301511835 -0700
committer Scott Chacon  1301511835 -0700
initial commit
$ git ls-tree -r cfda3bf379e4f8dba8717dee55aab78aef7f4daf
100644 blob a906cb2a4a904a152...   README
100644 blob 8f94139338f9404f2...   Rakefile
040000 tree 99f1a6d12cb4b6f19...   lib


  • Glob patterns:
    • '*', '?'
    • [abc] - any characrer inside brackets
    • [0-9]
  • End pattern with '/' to specify a directory
  • Negate pattern by starting it with '!'


git config diff.word.textconv strings
git config diff.exif.textconv exiftool
git config filter.indent.clean  indent
git config filter.indent.smudge cat
git config filter.dater.smudge expand_date (Ruby script in path)
git config filter.dater.clean 'perl -pe "s/\\\$Date[^\\\$]*\\\$/\\\$Date\\\$/"'


*.pbxproj binary      : Treats *.pbxproj files as binary data, won't try to convert or fix CRLF issues or print a diff
*.pbxproj -crlf -diff : Same
*.doc diff=word       : Uses 'word' filter for any file that matches *.doc pattern
*.png diff=exif       : Uses 'exif' filter for any file that matches *.png pattern
*.c   filter=indent   : Runs C sources through the 'indent' program before committing
*.txt filter=dater    : Expands $Date$ keyword when *.txt files are checked out


Ways to name a commit:

Name Example Description
branchname master


The name of any branch is simply an alias for the most recent commit on that "branch". Branch aliases change each time a new commit is checked in to that branch.
tagname v0.2


A tag-name alias is identical to a branch alias in terms of naming a commit, but tag aliases never change.
HEAD Currently checked out commit.
Full SHA-1 dae86e1950b1277e545cee180551750029cfe735
Partial SHA-1 e65s46 First 6 or 7 characters
Date spec master@{yesterday}

master@{1 month ago}

Ordinal spec master@{5} Nth prior value of the commit specified.
Carrot parent e65s46^^^^^




Nth parent of that commit.

^n is only useful for merge commits, which have more than one parent. The first parent is the branch you were on when you merged, the second is the commit on the branch that you merged in, etc.

name^^ - the parent of the parent of the given commit name

name^2 - second parent of the given commit name

Tilde spec e65s46~5


N-th generation grandparent of that commit, commit’s N-th ancestor.

name~10 = name^^^^^^^^^^

Tree pointer e65s46^{tree}


Tree of that commit reference (tree held by a commit), rather than the commit itself.
Blob spec master:/path/to/file



Blob under a particular commit or tree, a certain file within a commit’s content tree.

Public Key

ssh-keygen -t rsa -C ""
cd ~/.ssh

Local commands

git config

Priority 'git config' option Linux Windows
3 --system /etc/gitconfig <msysgit>/etc/gitconfig
2 --global ~/.gitconfig %HOME%/.gitconfig
1 --file (-f) .git/config .git/config

git config --list
git config --list --global (--system, -f)
git config
git config --global           "Evgeny Goldin"
git config --global          ""
git config --global             1/0
git config --global merge.conflictstyle diff3
git config --global core.autocrlf       true/false/input
git config --global core.whitespace     trailing-space,space-before-tab,-indent-with-non-tab,cr-at-eol
git config --global core.editor         emacs
git config --global color.ui            true
git config --global diff.external       extDiff
git config --global merge.tool     kdiff3 / tkdiff / meld / xxdiff / emerge / vimdiff / gvimdiff / diffuse / ecmerge / tortoisemerge / p4merge / araxis / opendiff
git config --global merge.tool    extMerge
git config --global mergetool.extMerge.cmd '...'
git config --global      status
git config --global alias.unstage "reset HEAD --"
git config --global alias.last    "log -1 HEAD"
git config --global alias.visual  "!gitk"

git clone

  • "Pro Git" - Transfer Protocols
  • Understanding Git: Collaborating
  • 'git clone' = 'git init' + 'git fetch'
  • Copies all the git objects to a new directory, checks you out a single local branch named the same as the HEAD branch on the cloned repo (normally 'master'), stores all the other branches under a remote reference by default named 'origin'
  • Automatically creates a local 'master' branch that tracks remote 'origin/master' branch on the server you cloned from (assuming the remote has a master branch)

git clone --bare my_project my_project.git  : Clones repository to create a new bare repository. By convention, bare repository directories end in .git.
                                            : ~ "cp -Rf my_project/.git my_project.git"
git clone /opt/git/project.git              : Tries to use hardlinks or directly copy the files it needs
git clone file:///opt/git/project.git       : Fires up the processes that it normally uses to transfer data over a network which is generally a lot less efficient.
                                              Can be used if you want a clean copy of the repository with extraneous references or objects left out.
git clone ssh://user@server:project.git     : SSH protocol
git clone user@server:project.git           : Same
git clone server:project.git                : Same, assumes user you're currently logged in
git clone git://  : Git protocol
git clone : HTTP protocol

git status

Header Description Next Undo
"Changes to be committed" Staged git commit git reset HEAD <file>
"Changed but not updated" Unstaged (modified) git add, git commit -a git checkout -- <file>
"Untracked files" Untracked git add Remove / .gitignore

git log

git log -p -2           : Generates patch, limits the number of commits to show
git log --stat          : Generates a diffstat
git log --graph         : Draws a text-based graphical representation of the commit history on the left hand side of the output
git log --no-merges     : Does not print commits with more than one parent
git log --abbrev-commit : Shows only a partial SHA-1 prefix instead of showing the full 40-byte hexadecimal commit object name
git log -g              : Shows reflog information, instead of walking the commit ancestry chain, walks reflog entries from the most recent one to older ones
git log --oneline --decorate
git log --pretty=oneline / short / medium / full / fuller / email / raw
git log --pretty=format:"..."
git log --pretty="..."

Commit Ranges:

git log master..experiment  : (D, C) Shows all commits reachable by 'experiment' that aren't reachable by 'master'
git log experiment..master  : (F, E) Shows all commits in 'master' that aren't in 'experiment'
git log origin/master..HEAD : Shows what you're about to push to a remote
git log origin/master..     : Same, 'HEAD' is default
git log master...experiment : (F, E, D, C)
                            : Specifies all the commits that are reachable by either of two references but not by both of them.
                            : Shows what is in 'master' or 'experiment' but not any common references.
git log --left-right master...experiment
< F
< E
> D
> C
git log contrib --not master      : Commits that are in 'contrib' branch but that aren't in 'master' branch
git log origin/featureA ^featureA : See what changed in 'origin/featureA', exclude local commits on 'featureA' branch
                                  : "foo ^bar" = "send me all object IDs which I need to download if I have the commit object bar, but not foo".
git log --no-merges origin/master ^issue54
git log refA..refB                : Identical
git log ^refA refB                : Identical
git log refB --not refA           : Identical
git log refA refB ^refC           : Identical
git log refA refB --not refC      : Identical
git shortlog --no-merges master --not v1.0.1 : Summary of all the commits since your last release 'v1.0.1'

git add

git add [files]
git add -i      : Interactive Staging
git add -p      : Staging Patches
git add --patch : Same

git replace

git rm

git diff

git diff
git diff --staged  : View changes staged for the next commit
git diff --check   : Warns if changes introduce trailing whitespace or an indent that uses a space before a tab, exits with non-zero status if problems are found
git diff --stat    : Generates a diffstat
git diff --numstat : Similar to '--stat', but shows number of added and deleted lines in decimal notation and pathname without abbreviation
git diff master           : Compares the snapshots of the last commit of the topic branch you're on and the snapshot of the last commit on the 'master' branch.
                          : If 'master' branch has moved forward since you created the topic branch from it, then you'll get seemingly strange results.
                          : If master is a direct ancestor of your topic branch, this isn't a problem; but if the two histories have diverged,
                          : the diff will look like you're adding all the new stuff in your topic branch and removing everything unique to the master branch.
git diff master...contrib : Diffs between the last commit of the branch you're on and its common ancestor with another branch,
                          : shows only the work your current topic branch has introduced since its common ancestor with master.
git diff a11bef06a3f65..cf25cc3bfb0 -- <file>
git diff master..experiment > patch.file
patch -p1 < patch.file

git commit

  • "Pro Git" - Commit Guidelines
  • Git stores a commit object that contains a pointer to the snapshot of the content you staged, the author and message metadata, and zero or more pointers to the commit or commits that were the direct parents of this commit: zero parents for the first commit, one parent for a normal commit, and multiple parents for a commit that results from a merge of two or more branches.
  • Don't amend your last commit if you've already pushed it

git commit
git commit -am 'Commit message'
git commit -a          : Automatically stages files that have been modified and deleted
git commit -v          : Shows unified diff between the HEAD commit and what would be committed
git commit --no-verify : Bypasses the pre-commit and commit-msg hooks

Commit message template:

Short (50 chars or less) summary of changes
More detailed explanatory text, if necessary.  Wrap it to about 72
characters or so.  In some contexts, the first line is treated as the
subject of an email and the rest of the text as the body.  The blank
line separating the summary from the body is critical (unless you omit
the body entirely); tools like rebase can get confused if you run the
two together.
Further paragraphs come after blank lines.
 - Bullet points are okay, too
 - Typically a hyphen or asterisk is used for the bullet, preceded by a
   single space, with blank lines in between, but conventions vary here

Change, reorder, squash, split commit messages:

git commit --amend   : Amends the tip of the current branch, commit you create replaces the current tip
                     : If no files are staged - only commit message is updated, otherwise current staging area is made the snapshot for the new commit
git rebase -i HEAD~3 : Changes multiple commit messages
git commit --amend
git rebase --continue

git filter-branch

git filter-branch --tree-filter 'rm -f passwords.txt' HEAD : Removes 'passwords.txt' from entire history
git filter-branch --tree-filter 'rm -f *~' HEAD            : Removes all accidentally committed editor backup files
git filter-branch ... --all                                : Rewrites all branches and tags
git filter-branch --subdirectory-filter trunk HEAD         : Makes the 'trunk' subdirectory be the new project root for every commit, new project root is what was in the 'trunk' subdirectory each time

git notes

git notes add HEAD
git notes add/edit -m 'I approve - Scott' master~1
git notes --ref=bugzilla add -m 'bug #15' 0385bcc3
git log
git log --show-notes=bugzilla
git log --show-notes=*
export GIT_NOTES_REF=refs/notes/bugzilla : '--ref' and '--show-notes' options are not necessary, default is 'bugzilla' now
git push origin refs/notes/bugzilla
git push origin refs/notes/*

git grep

git grep -n     log_syslog tag1 tag2 tree1 tree2 -- *.c
git grep -n  -c log_syslog tag1 tag2 tree1 tree2 -- *.c
git grep -n  -c maven master -- **/*.xml
git grep -L  -v git tag1 tag2

git stash

  • "Pro Git" - Stashing
  • Takes the dirty state of your working directory — that is, your modified tracked files and staged changes — and saves it on a stack of unfinished changes that you can reapply at any time.
  • Having a clean working directory and applying the stash on the same branch where it was created aren't necessary to successfully apply a stash:
    • You can save a stash on one branch, switch to another branch later, and try to reapply the changes.
    • You can have modified and uncommitted files in your working directory when you apply a stash. Git gives you merge conflicts if anything no longer applies cleanly.

git stash
git stash list
git stash show stash@{1}
git diff  stash@{1}
git reflog                      : reflog persists independently of other changes in repository
git reflog show stash           :
git log stash@{32}              : When did I do it?
git show stash@{32}             : What I was working on?
git checkout -b temp stash@{32} : Let’s see that old working tree!
git stash clear                               : DON'T! You'll lose all stash history
git reflog expire --expire=30.days refs/stash : Outputs the stash bundles that've been kept
git stash apply         : Assumes the most recent stash and tries to apply it
git stash apply --index : Tries to reinstate not only the working tree's changes, but also the index's ones
git stash apply stash@{1}
git add
git commit
git stash drop [stash] : Removes a single stashed state from the stash list
git stash pop  [stash] : Removes a single stashed state from the stash list and applies it on top of the current working tree state
git stash show -p stash@{0} | git apply -R : Un-applies a Stash
git stash show -p | git apply -R           : Same, assumes the most recent stash
git stash branch newBranch : Creates a new branch, checks out the commit you were on when you stashed, reapplies your work there, drops the stash if it applies successfully

git tag

git tag                         : List all tags
git tag -l 'v1.4.2.*'           : List tags with names that match the given pattern
git tag    v0.1                 : Lightweight tag (don't supply the '-a', '-s', or '-m' option), a branch that never moves
                                : Updates '.git/refs/tags' only
git tag -a v0.1 -m 'my message' : Annotated tag, doesn't need to point to a commit; any Git object can be tagged
                                : Updates '.git/refs/tags' and '.git/objects/'
git tag -a v1.2 [<commit>|<object>]
git push origin [tagname]       : Transfer tags to remote server
git push origin --tags          : Transfer all of your tags to the remote server that are not already there
git push origin refs/tags/*     : Same
git tag -d tagName                 : Delete local tag
git push origin :refs/tags/tagName : Delete remote tag

git archive + describe

git-archive --prefix=simplegit/ v0.1 | gzip   > simple-git-0.1.tar.gz
git-archive --format=zip        master^ lib/  >
git archive master --prefix='project/' | gzip      > `git describe master`.tar.gz
it archive master --prefix='project/' --format=zip > `git describe master`.zip

git bisect

git bisect start           : Starts the session
git bisect bad             : Marks known bad version
git bisect good v1.0       : Marks known good version
git bisect start HEAD v1.0 : Same
git bisect good/bad        : Marks currently checked out commit as good or bad
git bisect reset           : Stops the session, returns tree to the commit that was checked out before 'git bisect start'

Branch Commands

git checkout

git checkout -- <file>                      : Undoes unstaged (modified) changes
git checkout -b [branch]                    : Creates a new branch and starts it at HEAD
git checkout {--ours|--theirs} <file>       : Uses one of versions as merge resolution when inside a merge
git checkout -b serverfix origin/serverfix  : Bases 'serverfix' branch off remote branch
git checkout --track origin/serverfix       : Same (shorthand)
git checkout --track story84 origin/story84 :

Detached HEAD

git checkout master^       : checkout parent of master
git checkout HEAD~2        : checkout grandparent of current HEAD
git checkout origin/master : checkout a non-local branch
git checkout tagname       : checkout a tag
git checkout -b newBranch      : re-attach the HEAD
git reflog show HEAD@{now} -10 : show recent tip of branches updates
git branch newBranch 7fdae94   : create a branch using reflog commit

git branch

git status               : Shows branch name in a comment
git branch               : Lists existing branches, current branch is highlighted with an asterisk
git branch -v            : Shows SHA-1 and commit subject line for each head, along with relationship to upstream branch (if any)
git branch -r            : Lists the available remote branches
git checkout -b [branch] : Creates a new branch and starts it at HEAD
git branch   -d [branch] : Deletes a branch
git branch --track [new-local-branch] [remote-branch] : Set up a tracking branch to work with remote branch locally, 'git pull' with no arguments will merge the correct remote head.
git branch --track feature            origin/feature  : --track option is on by default

git merge

git merge
 .. resolve conflicts manually ..
git add
git merge-file             : Runs a three-way file merge
git mergetool              : Runs merge conflict resolution tools to resolve merge conflicts
git merge origin/serverfix : Merges remote branch 'origin/serverfix' into current local working branch

git rebase

  • "Pro Git" - Rebasing
  • Understanding Git: Rebasing
  • Git rebase explained
  • Do not rebase commits that you have pushed to a public repository, only rebase commits that have never been available publicly. Treat rebasing as a way to clean up and work with commits before you push them.
  • When you have work in a topic branch and have determined that you want to integrate it, you move to that branch and run the rebase command to rebuild the changes on top of your current master (or develop, and so on) branch. If that works well, you can fast-forward your master branch, and you'll end up with a linear project history.


git pull --rebase
git rebase master
1) Resolve manually + git add + git rebase --continue
2) git rebase --abort
3) git rebase --skip
git rebase [basebranch] [topicbranch]  : Checks out [topicbranch] and replay it onto [basebranch]
1) git rebase master server
2) git checkout master
3) git merge server
git rebase origin/master
git rebase -i
 .. edit commits
git rebase -i master
git rebase --onto master server client : Checks out the 'client' branch, figures out the patches from the common ancestor
                                       : of the 'client' and 'server' branches, and then replays them onto 'master'
git checkout master
git merge client
git rebase --whitespace=fix : Fixes whitespace issues as it's rewriting the patches

Remote commands

git remote

git remote -v
git remote add [shortname] [url]
git remote add local_proj /opt/git/project.git
git remote add mycap
git remote add official   git://
git remote show [remote-name]
git remote show origin
git remote rename [old-name] [new-name]
git remote rm [name] : Updates '.git/config' and '.git/refs/remotes/[remote_name]'.
                       It will not remove any of the git objects, so if you decide to add it again and fetch, very little will be transferred.

git fetch

  • Goes out to remote project and pulls down all data that you don't have yet. When done you should have references to all the branches from that remote which you can merge in or inspect.

git fetch origin
git merge origin/master
git push  origin master


git pull origin master
git push origin master

git pull

  • If you have a branch set up to track a remote branch, fetch + merge a remote branch into your current branch

git pull [remote-repository-reference] [remote-head-name]                     : Merges the head named [remote-repository-reference]/[remote-head-name] into HEAD
git pull origin/story84 = git fetch origin/story84 + git merge origin/story84 : Merges 'origin/story84' into local 'story84' branch
git pull --rebase
git pull git://

git push

  • 'origin' is default
  • If no arguments are given to "git push", it will push all the branches in the repository that are set up for tracking (every branch that you and the server have in common)
  • Git requires that the push result in a fast-forward merge on the remote repository. That means that, before the merge, the remote head points to an ancestor of the commit that it will point to after the merge.

git push [remote-repository-reference] [remote-head-name]: Adds new commit objects sent by the pushing repository
                                                           Sets [remote-head-name] to point to the same commit that it points to on the pushing repository
                                                           Updates the corresponding remote head reference on the sending repository
git push origin serverfix
git push origin serverfix:serverfix
git push origin serverfix:awesomebranch
git push [remotename] [localbranch]:[remotebranch]
git push --force                          : Usually, 'git push' refuses to update a remote ref that is not an ancestor of the local ref used to overwrite it.
                                            This flag disables the check. This can cause the remote repository to lose commits.
git push origin [tagname]                 : Transfer tags to remote server
git push origin --tags                    : Transfer all of your tags to the remote server that are not already there
git push origin refs/tags/*               : Same
git push --set-upstream origin new-branch : Create a new branch on the remote repository.
                                            For every branch that is up to date or successfully pushed, add upstream (tracking) reference.
git push [remote-repository-reference] :[head-name] : Delete a branch on the remote repository
git push [remotename]                  :[branch]
git push origin                        :serverfix

git request-pull

  • Takes the base branch into which you want your topic branch pulled and the Git repository URL you want them to pull from, and outputs a summary of all the changes you're asking to be pulled in.

$ git request-pull origin/master myfork : myfork => origin/master
The following changes since commit 1edee6b1d61823a2de3b09c160d7080b8d1b3a40:
  John Smith (1):
        added a new function
are available in the git repository at:
  git://githost/simplegit.git featureA
Jessica Smith (2):
      add limit to log function
      change log output to 30 from 25
 lib/simplegit.rb |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

git format-patch + send-email


  folder = "[Gmail]/Drafts"
  host = imaps://
  user =
  pass = p4ssw0rd
  port = 993
  sslverify = false

git format-patch -M origin/master : Prepares each commit with its patch in one file per commit
git send-email *.patch            : Takes the patches given on the command line and emails them out


+refs/heads/master:refs/remotes/origin/master        : <src>:<dst> (references pattern on the remote side:local storage)
                                                       '+' updates the reference even if it isn't a fast-forward
+refs/heads/*:refs/remotes/origin/*                  : Default for 'git fetch'
git log origin/master                                : Identical
git log remotes/origin/master                        : Identical
git log refs/remotes/origin/master                   : Identical
git fetch origin master:refs/remotes/origin/mymaster : Pulls the 'master' branch on the remote down to 'origin/mymaster' locally
git fetch origin master:refs/remotes/origin/mymaster \
git push origin master:refs/heads/qa/master          : Pushes 'master' branch to 'qa/master' on the remote server
git push origin :topic                               : Deletes <dst> ref from the remote repository
                                                       Makes 'topic' branch on the remote nothing


[remote "origin"]
       url =
       fetch = +refs/heads/*:refs/remotes/origin/*
[remote "origin"]
       url =
       fetch = +refs/heads/master:refs/remotes/origin/master
       fetch = +refs/heads/experiment:refs/remotes/origin/experiment
[remote "origin"]
       url =
       fetch = +refs/heads/master:refs/remotes/origin/master
       fetch = +refs/heads/qa/*:refs/remotes/origin/qa/*
[remote "origin"]
       url =
       fetch = +refs/heads/*:refs/remotes/origin/*
       push = refs/heads/master:refs/heads/qa/master




  • Aren't transferred during a clone!

Hook When Parameters Possible Purpose
pre-commit Before obtaining the proposed commit log message and making a commit 0 Inspect the snapshot
prepare-commit-msg After preparing the default log message, and before the editor is started 1-3 Edit default commit message
commit-msg After commit message is stored in a file 1 Validate project state or commit message
post-commit After a commit is made 0 Notification
pre-rebase Before rebase 0 Prevent a branch from getting rebased
post-checkout After successful 'git checkout' 3 Set up working directory, perform repository validity checks
post-merge After successful 'git merge' 1 Restore metadata associated with the working tree (permissions/ownership)


Hook When Parameters Possible Purpose
pre-receive After 'git push' is done on local repository, just before starting to update refs on remote repository Stdin Make sure none of the updated references are non-fast-forwards; check user access
post-receive After 'git push' is done on a local repository, after all the refs have been updated Stdin E-mailing a list, notifying a CI server, updating a ticket-tracking system.
Client doesn't disconnect until it has completed!
update After 'git push' is done on a local repository, before updating the ref on the remote repository. Runs once per branch. 3 Enforce a "fast-forward only" policy


git gc
git config --global 1/0
git fsck            : Verifies the connectivity and validity of the objects in the database
git fsck --full     : Checks also objects found in alternate object pools and in packed git archives
git prune           : Prunes all unreachable objects from the object database
git prune -n        : Doesn't remove anything, reports would be removed

Undoing things

Command Description
git checkout . Revert changes made to the working copy.
git reset Revert changes made to the index.
git revert Revert existing commits.
git reset --hard HEAD Reset the working directory and index back to the contents of the last commit (what it was before you tried the merge).
git reset --hard ORIG_HEAD Throw away last commit, undo the latest change or changes.
git reset HEAD <file>

git reset -- <file>

Unstage files, undo "git add", copy files from the latest commit to the stage.

"git reset" unstages everything.

git checkout -- <file> Undo local unstaged changes, copy files from the stage to the working directory, throw away local changes.
git stash show -p [stash] | git apply -R Un-apply a stash.
git filter-branch Rewrite branches.


Personal tools