From Omnia
Jump to: navigation, search



Git - Fast Version Control System

"Git is...
Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
Git is easy to learn and has a tiny footprint with lightning fast performance. It outclasses SCM tools like Subversion, CVS, Perforce, and ClearCase with features like cheap local branching, convenient staging areas, and multiple workflows."


Git is...
Git is an open source, distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
Every Git clone is a full-fledged repository with complete history and full revision tracking capabilities, not dependent on network access or a central server. Branching and merging are fast and easy to do.

Git (software) - Wikipedia:

"Git is a free distributed revision control, or software source code management project with an emphasis on being fast. Git was initially created by Linus Torvalds for Linux kernel development.
Every Git working directory is a full-fledged repository with complete history and full revision tracking capabilities, not dependent on network access or a central server."


Git/OpenWest 2016 Git Basics


	name = Kenneth Burgener
	email =

To set from the command line:

git config --global "Kenneth Burgener"
git config --global


Linus Torvalds has quipped about the name "git", which is British English slang for a stupid or unpleasant person:

"I'm an egotistical bastard, and I name all my projects after myself. First Linux, now git."

Custom Bash Prompt

Customize your Bash prompt - makandropedia -

GIT adds a __git_ps1 function that will output your branch. You can add onto it by specifying a string argument. A '%s' in the string will be replaced by the branch. I configured it to also show the short hash. Below is how I did it:

get_sha() {
    git rev-parse --short HEAD 2>/dev/null

get_hg_id() {
    id="$(hg id -bt 2> /dev/null| sed -r 's/[\(\)]+//g')"
    if [ -n "$id" ]; then
        echo "($id)"

PS1=$PS1'\[\033[00;35m\]$(__git_ps1 "(%s $(get_sha))")$(get_hg_id)\[\033[00m\]'
PS1=$PS1'\[\033[01;38m\]\$\[\033[00m\] '



gittutorial - A tutorial introduction to git (for version 1.5.1 or newer):

man gittutorial


Configure name and email:

$ git config --global "Kenneth Burgener"
$ git config --global


Initialize git repository:

git init    # current folder
git init .  # current folder
git init [dir]  # initialize folder (create folder if needed)


Clone an existing repository:

git clone [repo]           # clone [repo] to local dir named [repo] (only current branch)
git clone [repo] [newrepo] # clone [repo] to new local dir named [newrepo]


Add files to be tracked:

git add .
git add [file1] [file2] ...

add removed

To add commits with 'rm' or 'mv': [1]

git add -u

To stage your whole working tree:

git add -u :/

To stage just the current path:

git add -u .

To handle only removed files:

git rm `git ls-files -d`
# or
git ls-files -z -d | xargs -0 --no-run-if-empty git rm

XY problem: [2]

git commit -a
which would automatically pick up deletions, committing current state of tracked files in working directory
git add -A
which would add not ignored untracked files and remove no longer existing files, e.g. if you want to create commit from sideways update of working directory, e.g. unpacking a snapshot or result of rsync.


Commit changes:

git commit       # include only 'added' files
git commit -a    # also include modified tracked files
git commit -a -m 'message' # specify message


Show status: (shows: Changes to be committed, Changed but not updated, Untracked files)

git status


View commit log:

git log
git log -p  # diffs at each step
git log --stat --summary  # overview
git log --stat  # show files with change summaries
git log --name-only  # show files only
git log --name-status  # show file names with simple mod attribute
git log --name-status HEAD^..HEAD
git log -1 --stat  # show last commit stats
git log -n 8 --oneline --graph --decorate


Graphical Log: (ascii art)

git log --graph

--- glog - a git log alias for a decent view of your repo [3]

To create this alias, add the following to your .gitconfig

  glog = log --all --pretty='format:%d %Cgreen%h%Creset %an - %s' --graph


git show    # show summary and diff of current position
git show --summary    # show summary of current position

git id

git show could be used as a git id:

git show
git show --summary
git show -q  # seems to work like --summary but not mentioned
git rev-parse HEAD       # hash only
git show -s --format=%H  # hash only
git show -s --format=%h  # short hash


id = rev-parse HEAD
sha = rev-parse HEAD


See difference between changes and committed:

git diff    # Show only changes not added to the index
git diff --cached
git diff HEAD..origin  # show change between fetch and pull
git diff origin/master
git diff HEAD@{1}  # show changes since before the last pull
git diff HEAD@{1} [filename]   # same, but specify file
git diff HEAD^
git diff HEAD^ -- /foo/bar/baz.txt
git diff [shaOfHisCheckIn]^ [shaOfHisCheckIn]
git diff [shaOfHisCheckIn]{^,}

After doing a 'git fetch':

 git log HEAD..origin



git branch              # list branches - master is default
git branch [branch]     # create branch
git checkout [branch]   # checkout desired branch
git merge [branch]      # merge desired branch into current branch
git branch -d [branch]  # delete merged branch (close a branch)
git branch -D [branch]  # Terminate with extreme prejudice


Merge branches:

git merge [branch]  # merge [branch] into current branch

Merge 'test' branch back into master:

git checkout master
git merge 'test'

To close (delete) the merged branch:

git branch -d 'test'


Merge clones and pull from remote:

git pull [repo] [branch]    # pull changes from another clone

Dry run:

git pull --dry-run

To try a pull without staving:

git pull --no-commit
git reset --merge

Dry run: [4]

git fetch origin && git merge origin/master --no-commit --no-ff && git reset --merge

After a dirty pull merge to clean up log:

git rebase origin/master


Working with Remotes:

git fetch [repo] [branch]             # pull change info only (safe)
git log -p HEAD..FETCH_HEAD           # review changes
git remote add [RemoteName] [RemoteRepoURL]   # add remote repo
git remote -v                         # list remote repos
git branch -r                         # list remote repos branches
git fetch [rrepo]                     # pull changes info
git log -p [branch]..[rrepo]/[branch] # see changes to remote repo compared to local
git merge [rrepo]/[branch]            # merge remote branch to local
git pull . remotes/[rrepo]/[branch]   #  alternate form of merge

git pull                              # can pull changes directly if is clone
git config --get remote.origin.url    # see what original clone was (origin)

git push origin master

Git Hub


    name = Kilo Force
    email =

Initial setup:

mkdir gittest
cd gittest
git init .
git add README.TXT
git commit -m 'initial commit'
git remote add origin
git push origin master
git clone
git add file.txt
git commit -a -m 'file commit'
git push


git tag                # list tags
git tag [tag]          # tag current position
git log master..[tag]  # show logs from master to tag
git log [tag]..master  # show logs from tag to master (rev)
git checkout [tag]     # update to certain tag
git describe           # show the current tag


Show what will be deleted:

git clean -n

To Clean:

git clean -f

Remove directories:

git clean -fd

Remove ignored files:

git clean -fX

Remove ignored and non-ignored files:

git clean -fx

Ref: [5]



Reset whole tree: (revert changes) [6]

# won't touch new files
git reset --hard HEAD^    # reset to head (does not rm new files)
git reset --hard HEAD     # return the entire working tree to the last committed state

revert like

re-checkout all files, overwriting any local changes. This is most similar to "svn revert" if you're used to Subversion commands:

git checkout .

Reset on file:

git checkout -- hello.rb
git checkout HEAD hello.rb

rollback like

rollback or undo the last commit [7]

git reset --soft HEAD~
git commit -m "Something terribly misguided"
git reset --soft HEAD~
<< edit files as necessary >>
git add ...
#git commit -c ORIG_HEAD
#git commit -a -m "Something right"


Stash changes

git stash
git stash save "message"

Apply last change without deleting:

git stash apply

Apply last change with deleting:

git stash pop

Delete last stash:

git stash drop
git stash drop stash@{1}  # drop stash 1

List stashes:

git stash

Show files in last stash:

git show


(similar to annotate / amend commit message)

Changing a commit message [8]

git commit --amend

Change author:

git commit --amend --author="Author Name <>"

Changing an older commit with rebase: [9]

git rebase -i [change_set_prior_to_target]
# change "pick" for target changesets
git commit --amend --author="Author Name <>"
git rebase --continue
# or
git commit --amend --reset-author --no-edit


git submodule init
git submodule sync
git submodule update
# or
git submodule update --init --recursive

Show submodule commit versions and branches:

git submodule status


Manual Installation

Remove existing:

yum remove git
apt-get remove git

Install dependencies:

yum -y install gcc make curl-devel openssl-devel expat-devel autoconf gettext
# ? perl-ExtUtils-MakeMaker
sudo apt-get install curl libcurl4-openssl-dev libexpat1-dev gettext zlib1g-dev autoconf

Download Git source:


mkdir -p ~/.src ; cd ~/.src
# wget$GIT_VER.tar.gz
tar -zvxf git-$GIT_VER.tar.gz
cd git-$GIT_VER

Configure install:

make configure
# ./configure --prefix=/opt/git
make clean
make all
sudo make install

Git man pages: (optional step)

mkdir -p ~/.src ; cd ~/.src
# wget$GIT_VER.tar.gz
sudo tar -zvxf git-manpages-$GIT_VER.tar.gz -C /opt/git/share/man/

Paths: /etc/bashrc

export PATH=/opt/git/bin:$PATH
export MANPATH=/opt/git/share/man/:$MANPATH
echo -e "\n\nexport PATH=/opt/git/bin:\$PATH\n" >> ~/.bash_profile
echo -e "\n\nexport MANPATH=/opt/git/share/man/:\$MANPATH\n" >> ~/.bash_profile

Other Installation Options

Manually install man pages:

# dependencies: (need RPMforge)
#   yum install asciidoc libxslt xmlto
make man
sudo make install-man
  export PATH=/opt/git/bin:$PATH
  export MANPATH=/opt/git/share/man/
# direct usage
man -M ~/share/man git-commit
# or
export MANPATH=~/share/man
man git-commit

Personal install: (non configure method)

# personal install ~/bin ~/lib ~/share ... (prefix=~):
make install

Global install: (non configure method)

$ make prefix=/usr/local all doc info
sudo make prefix=/usr/local install install-doc install-html install-info

Installation with DAG

Install with DAG:

rpm -Uvh
yum install rpmforge-release  # update rpmforge
yum install git

FreeBSD Installation

 pkg_add -r git

Create Central Repo

Create a shared bare repo:

## Set permission
umask 0002
mkdir git
chown :sharedgroup git
# chmod g+ws git
chmod g+s git
cd git
# git init --bare some_project.git
# git clone --mirror some_existing_project.git
# git init --bare --shared some_project.git
mkdir some_project.git ; cd some_project.git
git init --bare --shared .
## Fix permissions and ownership
# chown some_project.git :sharedgroup -R
# find some_project.git -type d -exec chmod g+ws {} \;
# config - with shared setting
        repositoryformatversion = 0
        filemode = true
        bare = true
        sharedrepository = 1
        denyNonFastforwards = true

Central Repo

git clone [workingrepo] [dir] --mirror  # create bare repo  (ie dir='central')
## Make group editable:
find test-git.git -type d -exec chmod g+s {} \;
chmod g+w test-git.git -R
chown :git -R test-git.git/
git clone [repo]  # clone bare repo
... make changes and commit ...
git push  # push changes to repo
git clone oeey-git.git --mirror

Mirror Repo

Create local mirror:

git clone [URL] [dir] --mirror
cd [dir]
git update-server-info    # DON'T FORGET THIS STEP!

Sync Mirror

git remote update

cron job:

# 1 AM Sync git mirror
0 1 * * *       /usr/bin/git --git-dir=/git/some_git_repo.git remote update

Migrate Repo

mkdir new_repo
cd new_repo
git init .

cd ../old_repo
git remote add origin [path]/new_repo  # or url
# or manually modify .git/config to point to new repo

git push origin master

Git add is different

"Many revision control systems provide an add command that tells the system to start tracking changes to a new file. Git's add command does something simpler and more powerful: git add is used both for new and newly modified files, and in both cases it takes a snapshot of the given files and stages that content in the index, ready for inclusion in the next commit." [10]

cheat git

cheat git

Git Cheat Sheet - Guides - GitHub


Help.GitHub - Forking a project -

#Fork in GitHub

# setup
git clone
cd github-services
git remote add upstream git://
git fetch upstream

# push changes
git push origin master

# pull changes
#git fetch upstream
#git merge upstream/master
git pull upstream master



git-rm - Remove files from the working tree and from the index -


git-mv - Move or rename a file, a directory, or a symlink -


Committed history:

git log

Pretty one line logs: (last 3 logs)

git log --pretty=oneline -3


Diff of dirty, tracked files in the tree to the content added to the index:

git diff

Diff between index and HEAD of the current branch -- i.e. the changes that will be committed on git commit:

git diff --cached


Create patch:

git diff --no-prefix origin/master/HEAD > my_bugNNN.patch

Creating the patch: [11]

git format-patch [remote]/master --stdout > fix_empty_poster.patch

What changes in patch:

git apply --stat fix_empty_poster.patch

Test patch before applying (for conflicting files):

git apply --check fix_empty_poster.patch

Apply patch:

git apply fix_empty_poster.patch

Apply and signoff patch: (alternate to apply patch with signoff)

git am --signoff

Merge Conflict


List branches: (* indicates current)

git branch       # list local branches
git branch -r    # list remote branches
git branch -a    # list remote and local branches
git branch -v    # list local branches and source

Create branch:

git branch [BRANCH]  # local branch of current point in history:
git push origin origin:refs/heads/[BRANCH]  # remote empty branch

List origin of current checkout branch: (also lists remote branches)

git ls-remote

Checkout branch:

git checkout [BRANCH]     # checkout branch
git checkout [REMOTE]/[BRANCH]
git checkout [LOCALNAME] [REMOTE]/[BRANCH]
git checkout -b [BRANCH]   # create and checkout branch
git checkout --track -b [BRANCH]  # create and set push to use upstream (if not default)

Delete branch:

git branch -d [BRANCH]  # delete merged branch (close branch)
git branch -D [BRANCH]  # delete non merged branch - destructive
git push origin :[BRANCH]  # delete remote branch
git push origin :heads/[BRANCH]  # delete remote branch (not sure difference from previous)

Create/Push remote branch:

git push [REMOTE] [BRANCH]
git push origin [BRANCH]
git push origin origin:refs/heads/[BRANCH]  # remote empty branch

Merge (See #Merging)

git merge [BRANCH]   # merge branch into current

Determine branch of a detached head: [12]

git describe --contains --all HEAD
git log -n 1 --pretty=%d HEAD
git show -s --pretty=%d HEAD
git branch --contains HEAD  # not best

Automate creating remote branches: [13]

# git-create-branch <branch_name>
if [ $# -ne 1 ]; then
         echo 1>&2 Usage: $0 branch_name
         exit 127
set branch_name = $1
git push origin origin:refs/heads/${branch_name}
git fetch origin
git checkout --track -b ${branch_name} origin/${branch_name}
git pull


Create tag:

git tag [TAG]
git tag -a [TAG]  # with message using editor
git tag -a [TAG] -m 'message'  # with message

List tags:

git tag
git tag -l [PATTERN]
git show [TAG]  # show tag details and messages

Delete tag:

git tag -d [TAG]

Push tags to remote:

git push --tags

Get tags from remote:

git fetch

Show current tag: [14]

git describe
git describe --always --tag
git log --pretty=format:'%ad %h %d' --abbrev-commit --date=short -1


git-remote - manage set of tracked repositories -

Remote Git repository tracking


man git-remote
git help remote

Add remote:

git remote add test git://
# add and fetch remote details
git remote add test git:// -f

List remotes:

git remote
git remote show

Remote details:

git remote -v
git remote show [REMOTE]
git remote show origin

List origin of current checkout branch:

git ls-remote

Remove remote:

git remote rm [REMOTE]

Rename remote:

git remote rename [REMOTE]



Download objects and refs from another repository -

Fetch remote details:

git fetch -v
git fetch [REMOTE]

Checkout new branch from remote:

git checkout -b [LOCALNAME] [REMOTE]/[BRANCH]


git-pull - Fetch from and merge with another repository or a local branch -

Pull changes:

# Pull changes (git fetch followed by git merge)
# defaults to current branch from remote
git pull
git pull [remote_name]/[branch]
git pull origin master
git pull --dry-run  # don't actually do anything
You asked me to pull without telling me which branch you
want to merge with, and 'branch.bob.merge' in
your configuration file does not tell me, either. Please
specify which branch you want to use on the command line and
try again (e.g. 'git pull <repository> <refspec>').
See git-pull(1) for details.

If you often merge with the same branch, you may want to
use something like the following in your configuration file:

    [branch "bob"]
    remote = <nickname>
    merge = <remote-ref>

    [remote "<nickname>"]
    url = <url>
    fetch = <refspec>

See git-config(1) for details.


NOTE: only can push changes when the 'master' branch is checked out. Other branches do not appear to work.

git-push - Update remote refs along with associated objects -

Dry run:

git push --dry-run [...]

Push changes:

# defaults to current branch from remote
git push
git push remote_name my_branch:remote_branch

NOTE: One important thing is that you should push only to remote branches that are not currently checked out on the other side (for the same reasons you never switch to a remote branch locally)! Otherwise the working copy at the remote branch will get out of date and confusion will ensue.

Create/Push remote branch:

git push [REMOTE] [BRANCH]
$ git push [15] master:master
$ git push [16] master
$ git push [public-repo] master
You may force git push to perform the update anyway by preceding the branch name with a plus sign:
$ git push ssh:// +master

 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to ''
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.
git pull
git push -f

Failure of branch to push:

Push tag: [17]

# push all tags

Delete tag:

# You are literally telling git “push nothing into BRANCHNAME on REMOTENAME”

change remote

"Changing a remote’s URL - There is no direct command to change a remote’s URL, so you will usually run git remote rm followed by git remote add to change a URL. You can also edit the repo’s .git/config file directly to change the URL without re-fetching the remote." [18]

git remote rm [REMOTE]
git remote add [REMOTE]


To fetch new items from the git mirror, just do

git fetch

Then, you'll need to merge your changes with those in the head. Two options: rebase or merge.

If you haven't published your changes, you can just use rebase:

# git rebase [BRANCH]
git rebase master
git rebase origin/master

If there are conflicts, it will ask you to resolve them. After all is done, your commits will lie on top of those in git. Note that if one of your commits exactly matches changes made in git, it will silently disappear in rebasing.

An alternative is merging, which does not rewrite history,

# git merge [BRANCH]
git merge master



Merge branch into current branch

git merge [BRANCH]

Don't auto commit merge:

git merge [BRANCH] --no-commit

Git TUI merge tool:

git mergetool

Git User’s Manual - Resolving a merge -

Show changes to a conflicting file:

git diff [FILE]

During the merge, the index holds three versions of each file. Each of these three "file stages" represents a different version of the file:

$ git show :1:file.txt  # the file in a common ancestor of both branches
$ git show :2:file.txt  # the version from HEAD.
$ git show :3:file.txt  # the version from MERGE_HEAD.
# common base version of the file
git show :1:some_file.cpp
# 'ours' version of the file
git show :2:some_file.cpp
# 'theirs' version of the file
git show :3:some_file.cpp

Some special diff options allow diffing the working directory against any of these stages:

$ git diff -1 file.txt          # diff against stage 1
$ git diff --base file.txt      # same as the above
$ git diff -2 file.txt          # diff against stage 2
$ git diff --ours file.txt      # same as the above
$ git diff -3 file.txt          # diff against stage 3
$ git diff --theirs file.txt    # same as the above.

If you get stuck and decide to just give up and throw the whole mess away, you can always return to the pre-merge state with

$ git reset --hard HEAD

Or, if you’ve already committed the merge that you want to throw away,

$ git reset --hard ORIG_HEAD
git merge [rrepo]/[branch]            # merge remote branch to local
git pull . remotes/[rrepo]/[branch]   #  alternate form of merge



vimdiff [options] file1 file2
ctrl+w ctrl+w - switch windows
do - diff obtain change (do below missing)
dp - diff push changes
[c - previous difference
]c - next difference
:diffupdate - diff update ;)
:syntax off - syntax off
zo - open folded text
zc - close folded text

Change Commit Message

Change last commit message with:

git commit --amend
git commit --amend -m "some message"

Compress Repository

Ensuring good performance -

On large repositories, git depends on compression to keep the history information from taking up too much space on disk or in memory.

This compression is not performed automatically. Therefore you should occasionally run git-gc(1):

$ git gc

to recompress the archive. This can be very time-consuming, so you may prefer to run git gc when you are not doing other work.


gitignore - Specifies intentionally untracked files to ignore -

Patterns read from a .gitignore file in the same directory as the path, or in any parent directory, with patterns in the higher level files (up to the toplevel of the work tree) being overridden by those in lower level files down to the directory containing the file

Patterns read from $GIT_DIR/info/exclude

   $ cat Documentation/.gitignore
   # ignore generated html files,
   # except foo.html which is maintained by hand

Archive (Export)

git-commit - Record changes to the repository


man git-archive
git help archive

SVN calls this export, Git calls this archive.

Simple method:

  • git clone followed by removing the .git repository directory.

Export project:

git archive master | tar -x -C /somewhere/else

Export and compress:

git archive master | bzip2 >source-tree.tar.bz2

Zip archive:

git archive --format zip --output /full/path master

Prefix folder in zip:

git archive --format zip --output /path/to/ --prefix=newdir/ master

git export:

git checkout-index -a -f --prefix=/destination/path/
git checkout-index --prefix=git-export-dir/ -a

with remote:

git-archive --format=tar --remote=ssh://remote_server/remote_repository master | tar -xf -

other: [19]

git archive HEAD | (cd ~/path/where/I/want/it/ && tar -xvf -)
rsync path/I/want/to/export/ -ri --del -m --exclude ".*" ~/path/where/I/want/it/ |grep sT

other 2: [20]

git archive master | gzip > latest.tgz
git archive master | bzip2 > latest.tar.bz2


Git Server

How to set up your own private Git server on Linux | Bradley Wright (using SSH)

?? (using git-daemon)

man git-daemon
yum install git-daemon

Destructive Operations

Rewrite Commit Authors

List authors:

git log --all --format='%aN <%aE> - %cN <%cE>' | sort -u

Redo all commits:

for i in 1 2 ; do
git filter-branch -f --tag-name-filter cat --commit-filter '
        git commit-tree "$@"' -- --all

Note: will need a '-f' to overwrite backup if you ever run a second time.

Rewrite certain commits:

for i in 1 2 ; do
git filter-branch --tag-name-filter cat --commit-filter '
        if [ "$GIT_AUTHOR_NAME" = "Ryan" -o "$GIT_AUTHOR_NAME" = "Ryan Test" ];
                GIT_AUTHOR_NAME="Ryan Test";
                GIT_COMMITTER_NAME="Ryan Test";
        elif [ "$GIT_AUTHOR_NAME" = "Mike Test" ];
                GIT_AUTHOR_NAME="Mike Test";
        git commit-tree "$@"' -- --all

Fancier filter [21]


git filter-branch --env-filter '


case ${GIT_AUTHOR_NAME} in
        user1) n="User One" ; m="" ;;
        "User Two") n="User Two" ; m="" ;;

export GIT_AUTHOR_NAME="$n"
export GIT_AUTHOR_EMAIL="$m"


Git Read-Only: git://

Global setup:

Download and install Git
 git config --global "Kilo Force"
 git config --global

Next steps:

 mkdir test
 cd test
 git init
 touch README
 git add README
 git commit -m 'first commit'
 git remote add origin
 git push origin master

Existing Git Repo?

 cd existing_git_repo
 git remote add origin
 git push origin master

Importing a Subversion Repo:

When you're done:

Check out project:

git clone test
( modify files )
git commit -a -m 'changes'
git push
# git push

NOTE: don't check out from or you will get this error:

fatal: remote error:
  You can't push to git://

SVN for GitHub

Ever wanted to use SVN to grab code from GitHub? Well, now you can, and just like that GitHub is the world's biggest Subversion host. Here's a few things you might like to do with it:

  • Use any GitHub repository as an SVN external.
  • Use TortoiseSVN or your favorite SVN tool to view Git repositories.
  • Use existing build tools or continuous integrations systems that only work with SVN.

Check out projects through (http or https)

svn checkout test

Notice, on checkout there will be the following error that can be ignored.

REPORT of '/kiloforce/test.git/!svn/vcc/default': 200 OK (


Caching Password

authentication - Git push requires username and password - Stack Overflow -

The following command will save your password in memory for sometime. (For git 1.7.10 or newer.)

# Set git to use the credential memory cache
$ git config --global credential.helper cache
# Set the cache to timeout after 1 hour (setting is in seconds)
$ git config --global credential.helper 'cache --timeout=3600'

You can also add to your git config (in repo or common), to remember which user name:

[credential ""]
    username = kiloforce

Notch anti Git

Oh, and I’ve finally committed the Music Blocks to the repository.
(Oh, wait, no, I didn’t.. Doing so broke git, so we’re changing to svn because git is horrible and evil)

-- Notch (Jan 06, 2011)


Git vs the World

Why Git is Better Than X -

Git Quick Start

Cloning and Creating a Patch:

$ git clone git://
$ cd hello-world
$ (edit files)
$ git add (files)
$ git commit -m 'Explain what I changed'
$ git format-patch origin/master

Creating and Commiting:

$ cd (project-directory)
$ git init
$ (add some files)
$ git add .
$ git commit -m 'Initial commit'


GitFaq - GitWiki

Git - Documentation

Git User's Manual (for version 1.5.3 or newer)

Official Git Tutorial

SVN to Git Crash Course

Git for the lazy - Spheriki

Git Magic

Kernel Hackers' Guide to git


Git uses port 9418:

git clone git://

If you have problems connecting (Git uses port 9418), you can try to access the repository over the HTTP protocol:

git clone

Git vs SVN

git clone url svn checkout url
git pull svn update

Git Turotials

Git - SVN Crash Course


This includes links for binaries and source code.

gerrit - code review

gerrit - Gerrit Code Review - Google Project Hosting -

Web based code review and project management for Git based projects.

Gerrit is a web based code review system, facilitating online code reviews for projects using the Git version control system.

Gerrit makes reviews easier by showing changes in a side-by-side display, and allowing inline comments to be added by any reviewer.

Gerrit simplifies Git based project maintainership by permitting any authorized user to submit changes to the master Git repository, rather than requiring all approved changes to be merged in by hand by the project maintainer. This functionality enables a more centralized usage of Git. Resources

ssh config


Host myserver
  user bob
Host *
  user jenkins
Host gh-foo
    User git
    IdentityFile ~/.ssh/foo_github_id
Host gh-bar
    User git
    IdentityFile ~/.ssh/bar_github_id


Git for Mercurial users

Command equivalence table -

Git vs Mercurial - WikiVS -

See Git vs Mercurial

Convert Git to Mercurial

Really easy!

hg convert [git_repo] [hg_repo]

Convert Mercurial to Git

cd ~
git clone git://
git init git_repo
cd git_repo
~/fast-export/ -r /path/to/old/mercurial_repo
git checkout HEAD

Source: Convert Mercurial project to Git - Stack Overflow -

hg id

git rev-parse HEAD
# git rev-parse HEAD

incoming and outgoing

out = log --pretty=oneline --abbrev-commit --graph @{u}..
outgoing = log --pretty=oneline --abbrev-commit --graph @{u}..
in = !git fetch && git log --pretty=oneline --abbrev-commit --graph ..@{u}
incoming = !git fetch && git log --pretty=oneline --abbrev-commit --graph ..@{u}

Note: run "git fetch" first



Mimic 'hg incoming' and 'hg outgoing'

hg incoming:

git log ..@{u}

hg outgoing:

git log @{u}..
git config --global alias.incoming '!git remote update -p; git log ..@{u}'
git config --global alias.outgoing 'log @{u}..'
incoming = "!git remote update -p; git log ..@{u}"
outgoing = log @{u}..

Reference: mercurial - Using Git how do I find changes between local and remote - Stack Overflow -


Unable to find http helper


$ git clone git://
fatal: Unable to find remote helper for 'http'


  • The curl library was missing when git was compiled
  • Install curl-devel and recompile.

Connection Refused


$ git clone git://
Initialized empty Git repository in /data/store/home/kenneth/git-1.7.1/hello-world/.git/[0:]: errno=Connection refused
fatal: unable to connect a socket (Connection refused)


  • Open outbound TCP port 9418 on the Firewall

bash: git-upload-pack: command not found

$ git clone username@host:~/project/path/contactdb
Initialized empty Git repository in 
  c:/Documents and Settings/Administrator/My Documents/projects/contactdb/.git/
bash: git-upload-pack: command not found
fatal: The remote end hung up unexpectedly

Why is this git clone command failing? - Stack Overflow -

test with:

ssh [server] git-upload-pack


  • If this fails, add the path to the program to the user's .bashrc on the remote server

insufficient permission


error: insufficient permission for adding an object to repository database ./objects


sudo chown -R git:git repo.git/
sudo chmod -R gituser.gituser objects

git - Error pushing to GitHub - insufficient permission for adding an object to repository database - Stack Overflow -

ssl certificate verify failed


error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

Ignore ssl certificate verification: [22]

export GIT_SSL_NO_VERIFY=true
# or
git config --global http.sslverify false
git clone https://github...


insufficient permission for adding an object to repository database ./objects

$ git push origin master
error: insufficient permission for adding an object to repository database ./objects
fatal: failed to write object
error: unpack failed: unpack-objects abnormal exit

See shared setting:

git config core.sharedRepository
# "", "group", etc...
echo $?
# rc 0 means shared, rc 1 means NOT shared


cd /path/to/repo.git
chgrp -R groupname .
chmod -R g+rwX .
find . -type d -exec chmod g+s '{}' +
# set share setting
git config core.sharedRepository group  # set group shared
# Verify:
git config core.sharedRepository   # "group"

If you really hate permissions:

git config core.sharedRepository world

Not sure what level this does:

git config core.sharedRepository true



To Read

SVN for Git: