Git-Repository klonen
# clone repository to local directory
git clone https://github.com/sandreas/graft.git
Neuen Branch lokal anlegen
# Create a new local branch and switch to it
git checkout -b name_of_the_branch
Lokalen Branch ins Remote Repository übertragen
# Push a local branch to the remote repository
git push origin name_of_the_branch
Alle Branches / den aktuellen Branch anzeigen
# Show branches (active one is marked with *)
git branch
Änderungen und den Status anzeigen?
# show changes
git status
Änderungen commiten?
# add new files
git add .
# remove deleted files
git add -A
# commit changed files
git commit -m '<commit message>'
Änderungen temporär verwerfen
# revert all changes, but put it to a stash
git stash
# list all existing stashes
git stash list
# stash@{0}: WIP on master: 049d078 added the index file
# stash@{1}: WIP on master: c264051 Revert "added file_size"
# stash@{2}: WIP on master: 21d80a5 added number to log
# restore changes from a stash
git stash apply stash@{1}
Änderungen unwiederbringlich verwerfen
Für einen ganzen Branch
# Revert changes to modified files.
git reset --hard
# Remove all untracked files and directories. (`-f` is `force`, `-d` is `remove directories`)
git clean -fd
Für ein bestimmtes Verzeichnis
# revert the changes only in current working directory
git checkout -- .
# Revert changes to modified files.
git reset --hard
# Remove all untracked files and directories. (`-f` is `force`, `-d` is `remove directories`)
git clean -fd
Ein Changelog erstellen
# show all changes to head since stable tag, syntax: git log --oneline --no-merges <last tag>..HEAD
git log --oneline --no-merges stable..
Commit Statistik
# show commit statistics
git shortlog -sn
# or time based
git shortlog -sn --since='10 weeks' --until='2 weeks'
Weitere Tipps für nützliche git Befehle finden sich in diesem Artikel.