From XennisWiki
Jump to: navigation, search

Git is a version control system that is used for software development and other version control tasks. As a distributed revision control system it is aimed at speed, data integrity, and support for distributed, non-linear workflows. Git was created by Linus Torvalds in 2005 for development of the Linux kernel, with other kernel developers contributing to its initial development. (Wikipedia)

Download and installation

Arch Linux

pacman -S git


apt-get install git

To get the newest version on older systems

apt-add-repository ppa:git-core/ppa
apt-get update
apt-get install git


Download Git form the official site. On the side you will also find a selection of GUI Clients.



In general Eclipse comes with a build in Git support, but further information for especially GitHb you find on the side Git in Eclipse (Plugins EGit - Git Team Provider and GitHub Mylyn Connector are necessary).

Repository browser

  • Debian: apt-get install gitk



Display status

git status

Show commit log

git log

Rename file

git mv file.txt newFolder/newName.txt

Clone and commit

Clone a project

git clone [-b BRANCH-NAME] git@... [DESTINATION-FOLDER]

Add (-a) changes and commit these change with message (-m <text>)

git commit -a -m "Comment"


Create a tag and push it

git tag <tag-name>
git push origin <tag-name>

Delete a tag

git tag -d <tag-name>

Reset and revert changes

Reset local uncommitted changes (checkout, reset)

Display changes

git diff [--cached]

Reset (1) a single file or (2) all

git checkout path/example.txt
git checkout -- .

Reset the local uncommitted changes

git reset --hard

Revert merge commit

Exemplary merge commit, which you want to revert

commit  6a7cdb9f2d3c6d614f26e20e83cacc2707b37527
Merge: 95db9ea0 7c6b236
Merge branch 'master'

Use git revert with the option -m <parent-number> (merge). (1) Revert to commit 95db9ea0 (see message above) by using -m 1 or (2) revert to commit 7c6b236 by -m 2

git revert 6a7cdb9 -m 1
git revert 6a7cdb9 -m 2


Create and push a branch

(1) Create a branch and (2) push it

git checkout -b BRANCH-NAME
git push -u origin BRANCH-NAME

Delete a branch

(1) Delete a local branch and (2) delete a remote branch

git branch -d BRANCH-NAME
git push origin :OLD-NAME

Checkout branch and list all branches

Switch to branch

git checkout BRANCH-NAME

Display all branches

git branch -a


Init and update submodules (use --depth 1 for a shallow clone)

git submodule update --init [--recursive]

Checkout each submodule

git submodule foreach git checkout

Add a new submodule

git submodule add path/to/dir

Reset all submodules

git submodule foreach --recursive git submodule update --init


Delete all untracked files

List files (with option -n) to delete

git clean -f -n

Delete all untracked files from the working tree

git clean -f


see Git - Tips

Show current branch in terminal

Add to your ~/.bashrc the following line

export PS1='\u@$HOSTNAME \w$(__git_ps1 " (%s)")$ '

Bash auto-compleation

Further information: Git Basics - Tips and Tricks

Download the auto-completation file and copy it into /etc/bash_completion.d/.

Useful alias

Further information alias

    br = branch
    ci = commit -m
    co = checkout
    cp = cherry-pick
    ls = log -5 --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate
    pu = !git pull --rebase && git submodule update
    re = rebase --interactive
    st = status
    amend = commit --amend
    save = !git add -all && git commit -m 'SAVEPOINT'
    wip = !git add -u && git commit -m "WIP"
    wipe = !git add --all && git commit -qm 'WIPE SAVEPOINT' && git reset HEAD~1 --hard

Alias assing the shell

my-review = !sh -c 'git preview $1 $2' -

Push with SSH (on a repo cloned with HTTP)

git remote set-url origin

Error and problems

Check Home Directory

Further information: Setting up the Home Directory on Windows

Error message
Check Home Directory

The environmental variable HOME is not set. The following directory will be used for storing
the Git user configuration and as a default repository location: [...].
If this is not correct please set the HOME environment variable and restart Eclipse.

See also

External links