From Andreida
Jump to: navigation, search



  • a working directory is using a branch (might be master)
  • changes to files are NOT linked to a branch
  • "git add" is NOT linked to a branch, but says, I will later commit these files to my local repository
  • "git commit"+branch IS linked to a branch and adds the changes to the local repository in the given branch
  • "git push" uploads a branch to another repository (perhaps to another computer)
  • "git fetch" gets update/status information about the complete repository
  • "git pull" downlads updates for the current branch from another repository (perhaps from another computer)


Basic commands

  • get a repository
    • create one
git init
    • get one
git clone git://
  • look at it
git status
  • add a new file
git add <new file>
  • commit changes to your local repository
    • mark for send and send in one command
git commit -a -m 'committing all changed files'
    • do mark and send in two steps
      • mark for the commit
git add <file> 
      • commit
git commit -m 'message'
  • send data to server
    • check, what you would send to the server
git push -n
    • show changes which will be sent to the server
git diff <hash...hash_from-push-n>  
    • send commits to server, if you started the repository with clone
git push
    • delete a branch:
git branch -d <branch>
git push origin :<branch>


  • new branch
git branch <name> | git checkout -b <name>
  • switch to branch
git checkout <name>
  • merge branch/hotfix to the master
git checkout master
git merge <name> | git merge origin/<name> --no-ff
  • show existing branches (note the * marking the current one)
git branch
  • not merged yet
git branch --no-merge
  • revert a merge which has been done with --no-ff
git revert -m 1 hash_of_merge_commit
  • not pushed yet:
git log origin/master..master
  • list of changes that will be merged into current branch.
git log ..otherbranch
  • diff from common ancestor (merge base) to the head of what will be merged. Note the three dots.
git diff ...otherbranch
  • not pushed yet
git log --branches --not --remotes

Easier handling

auto complete

  • get the file
  • source it (in your .bashrc)
. git-completion.bash
  • try it
git co<tab><tab>


put these into your .bashrc

# simple history
alias gitree='git log --pretty=format:"%h - %an, %ar : %s" --graph'
# colors
# better histories, last 30, all
alias gitlol='git log --graph --decorate --pretty=format:"%Cgreen%h %Cred%ad%C(Yellow)%d %Cblue%an %Creset%s" --abbrev-commit --date=short -30'
alias gitlola='git log --graph --decorate --pretty=format:"%Cgreen%h %Cred%ad%C(Yellow)%d %Cblue%an %Creset%s" --abbrev-commit --date=short --all'
# prompt shall show info about the git branch
if [ -f /etc/bash_completion.d/git ]; then
   . /etc/bash_completion.d/git
   PS1=$Color_Off'[\t \u@\h]'$Color_Off' \w'$Blue'$(__git_ps1 " {%s}")'$Color_Off' \$ '$Color_Off
   PS1=$Color_Off'[\t \u@\h]'$Color_Off' \w \$ '$Color_Off
# diff via log or diff
alias gitdifflog='function git_log() { git log --graph --decorate --pretty=format:"%Cgreen%h %Cred%ad%C(Yellow)%d %Cblue%an %Creset%s" --abbrev-commit ..$1; };git_log'
alias gitdiff='function git_diff() { git diff --pretty=format:"%Cgreen%h %Cred%ad%C(Yellow)%d %Cblue%an %Creset%s" ...$1; };git_diff'


gitdifflog OtherBranch1
gitdiff OtherBranch1

Tutorials / Manuals



  branch = auto
  diff = auto
  status = auto

[color "branch"]
  current = yellow reverse
  local = yellow
  remote = green

[color "diff"]
  meta = black bold
  frag = magenta bold
  old = red bold
  new = green bold

[color "status"]
  added = yellow
  changed = green
  untracked = cyan

special commands

git reset

git reset will move your merge/add/commit actions to a point in history, undo them:

git reset --soft HEAD~1  // committed things are now only added
git reset --mixed HEAD~1 // committed things are not added anymore
git reset --merge        // all changes from "git merge" are removed
git reset --hard         // all changes since last push are removed
Personal tools