Git

Les branches

Supprimer une branche locale :

$ git branch -d ma-branche

Supprimer une branche distante :

$ git push origin --delete ma-branche

Renommer une branche locale :

$ git branch -m <newname>
$ git branch -m <oldname> <newname>

Les dépôts distants

Lister les dépôts distants :

$ git remote -v

Ajouter un dépôt distant :

$ git remote add upstream https://path/to/the/repo.git
$ git fetch upstream

Récupérer une branche sur un dépôt distant :

$ git fetch upstream rbranch:lbranch

Cloner un dépôt Git

$ git clone ssh://git@server:port/repo

Pour synchroniser les branches non reçues :

$ git checkout -b branche origin/branch_name

Reset de l’auteur

Remettre à zéro d’auteur entre un commit et HEAD :

git filter-branch -f --tree-filter "GIT_AUTHOR_NAME='MyUsername'; GIT_AUTHOR_EMAIL='myusername@example.com'" a7ef815a14753f6801b5a31142f5723085ea14c0..HEAD

Pour remettre à zéro le nom de la personne qui a fait le commit, il faut utiliser les variables GIT_COMMITTER_NAME et GIT_COMMITTER_EMAIL.

Retrouver un stash perdu

git fsck --unreachable | grep commit | cut -d" " -f3 | xargs git show
git stash apply {{commit id}}

Copier un commit sur un autre repository

Exporter le commit :

git format-patch a_big_feature_branch -1 1ecb5853f53ef0a75a633ffef6c67efdea3560c4 -o patches

Importer le commit dans l’autre repository :

git am patches/0001-a-nice-change-that-i-d-like-to-include-on-production.patch

Configuration

Activer la coloration :

$ git config --global color.diff auto
$ git config --global color.status auto
$ git config --global color.branch auto

Autres commandes

Commande Description
git diff --cached Affiche toutes les différences
git branch -m old_branch new_branch Renommer une branche
git reset --hard <commit> Revenir à une version antérieure
git clean -f Supprime les fichiers qui ne font plus tracké
git reset 'HEAD@{1}' Annule l’action pécédente
git reflog Affiche l’historique des actions
git reset --soft HEAD~ Défaire le dernier commit

Liens