Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 10 Current »


Global Settings



show current configuration

git config --global --list

command line colors

git config --global color.ui auto


git config --global

LF (LineFeed) on all platforms:

git config --global core.autocrlf input

use TextMate as default editor:

git config --global core.editor "mate -w"

use Sublime as default editor:

git config --global core.editor "subl -w"



git config --global alias.s "status"
git config --global alias.l "log --stat"
git config --global alias.lpo "log --pretty=oneline --abbrev-commit --graph --decorate"

git config --global alias.sync "!git pull & git push"

(shell command begins with '!')

example configurations from .gitconfig

  s = status
  lpo = log --pretty=oneline --abbrev-commit --graph --decorate
  orphank = !gitk --all `git reflog | cut -c1-7`&
  hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short

Commit Code Changes

git add



split changes into several commits

git add . -p

accept deleted into staging

git add -u .

shortcut to accept all changes

git add -A .

git commit



verbose display when committing

git commit -v

shortcut for commit message

git commit -a -m"This is my great message"

change last commit message while in staging

git commit --amend

Display Changes and Log



show log

git log

last commit of current branch

git diff HEAD

display log with rename and copy

git log --stat --C (for extended display use --find-copies-harder--)

difference to a specific repository

git diff HEAD remote/name/master

difference to a branch

git diff master feature1

show branch

git show-branch

display executed commands

git reflog

view local repository in browser

git instaweb --httpd webrick

tool to visualize git

gitk --all& (all branches)

Branches, Merges and Tags




show current branch

git branch

show all branches (including remote branches)

git branch -a

non-merged branches

git branch --no-merged

merged branches

git branch --merged

create branch

git branch name

go to a specific branch (also tags)

git checkout branchname


git checkout master

shortcut for creating a branch and checking it out

git checkout -b branchname

push branch changes

git push -u pushable branchname

get branch from repository

git checkout remotes/origin/branchname

change branch number of steps

git checkout master^^ (go back two steps)


git checkout master
git merge branchname




show tags

git tag -l

create tag

git tag tagname

remove specific tag

git tag -d tagname

tag with message

git tag -a tagname

push tags to (remote) repository

git push --tags (origin master) / git push (origin master) tagname / git push --all origin master

remove tag from (remote) repository

git push repo :tagname

Repositories Push, Fetch, Pull

Initialize Repository

create a directory and init with

git init
git add .
git commit

(git remote / git remote -v)

add repository to configuration

git remote add reponame https://schniebiwutz.git 

(goes to .git/config)

git pull/fetch reponame
git diff HEAD remotes/reponame/master

Difference Fetch / Pull

git pull: combination of git fetch and git merge, pulls and merges all changes to all your files

git fetch: fetches changes from the repository but does NOT update files changed locally


Several commits can be combined to one using the rebase command. Use this to clean up the commit history before pushing changes to a remote repository.

git checkout myfeaturebranch
git rebase master

Undo and Recovery

Restore accidentally deleted files

display deleted files

git ls-files -d

restore the deleted files

git ls-files -d | xargs git checkout -

Other Restore Commands

git reset HEAD

revert to last commit / version

git reset --hard
git reset --hard 78827

discard last commit but keep code

git reset --soft

discard local changes

git remote prune name (origin)

go back to a specific version

git revert 2F66a

clean commands

git clean -n
git clean -fd

emergency rescue

git reflog
git reset --hard 2727 (taken from reflog, if not already killed by GC)

edit last commit message

git commit --ammend

add note

git notes add master^^^^



stashing is only local

git stash
git stash list
git stash apply (this applies and leaves the changes in the stack as opposed to "pop")
git stash pop (back)
git stash branch newbranch
git stash branch newbranch stashname

Other commands

check all hashes

git fsck

check who created a file

git blame filename

Configure Specific Repositories


Take the content of the file


and paste it to the repository configuration.

Test SSH connections:

Github: ssh
Gitolite: ssh gitolite@localhost

get a verbose protocol by using

ssh -v

Github Repository

git remote add origin
git push origin master

Bitbucket Repository

git remote add origin
git push origin master

Git Resources

  • No labels