Top

Git

Ist eine Versionsverwaltung von Dateien.

Ein leeres Repository erzeugen

git init
git init ~/Documents/Test

Clone

git clone http://www.kernel.org/pub/scm/git/git.git mycopy
git clone git@github.com:whatever folder-name

git clone --bare git@github.com:whatever folder-name
git clone -b <branch_name> --single-branch <url_of_the_git_repo>

Dateien zum Repository hinzufügen

git add file1 file2 file3
git add .
git add *

Dateien aus Repository entfernen

git rm file1

git mv file1 file2

Status

git status

Anzeigen

git show
git show-branch --more=10

Log

git log
git log masters // gesamten Verlauf eines Repositories

git log --follow -p -- <file>

Reset

git reset --hard <commitid>
git reset --hard HEAD

git revert <commitid>..HEAD

Konfiguration

Git hat eine globale ud lokale Konfiguration, die globale findet man unter ~/.gitconfig. Die lokale Konfiguration ist im jeweiligen Repository unter .git/config zu finden. Die Konfigurationsdateien sind einfache Textdateien im .ini Format.

git config --global user.name "xxx"
git config --global user.email "xxx@test.de"

Um alle Einstellungen angezeigt zu bekommen kann git config -l genutzt werden. Eine Einstellung kann man einfach aus der Konfigurationsdatei löschen oder auf der Konsole ausführen.

git config --unset --global user.email

Remote

git remote set-url origin <newurl> <oldurl>

Commits

git commit -m "message"

Mit gitmoji kann man den Messages noch etwas Farbe mitgeben.

git commit -m ":bug: fixed the bug"

Den letzten Commit noch einmal anpassen.

git commit --amend

Pull/Push

git pull
git pull --rebase

git push

Die History überschreiben.

git push --force
git push --force-with-lease

git push --mirror

Branch

Lokalen Branch erstellen.

git branch my_branch

git push origin my_branch

Lokalen Branch erstellen, wenn Änderungen vorhanden sind.

git checkout -b my_branch

Löschen eines lokalen Branches.

git branch -d my_branch1 my_branch2

git branch -a
git checkout -b <localbranch> <remotebranch>

git push -u origin <newbranch> // push a feature branch

git push origin --delete <branch> // remove remote branch

Rebase

git fetch origin develop
git rebase origin/develop
gir push --force

Tags

git tag -l "v1.8.*"

git tag -a v1.4 -m "my version 1.4"

git push origin v1.5
git push origin --tags

git checkout -b version2 v2.0.0

Diff

git diff
git diff <Commit>
git diff --cached <Commit>
git diff <CommitA> <CommitB>

git diff <File>

Modules

.gitmodules

git submodule init
git submodule update