Laurent.Vanni @cnrs.fr
http://bcl.unice.fr/membres/Laurent.Vanni/formation/git/slides$ git clone https://src.koda.cnrs.fr/laurent.vanni.2/formationgit.git
$ git clone https://github.com/lvanni/formationGIT.git
Deux types :
Des fonctionnalités partagées :
Avantages
Défauts
Avantages
Défauts
Avantages
Défauts
Avantages
Défauts
LINUX
$ sudo apt-get install git-core
MacOS
Windows
Test
$ git --version
Votre Pseudo
$ git config --global user.name "pseudo"
Votre e-mail
$ git config --global user.email moi@email.com
Acces remote par https (automatisation par accesstoken)
$ git config --global --add credential.helper "store --file ~/.git-credentials"
$ vi ~/.git-credentials
$ chmod 0600 ~/.git-credentials
Pour voir la config actuelle et la supprimer
$ git config --global --get-all credential.helper
$ git config --unset credential.helper
$ git credential-cache exit
$ git config --global color.ui true
$ git config --global color.diff auto
$ git config --global color.status auto
$ git config --global color.branch auto
Votre éditeur de texte
$ git config --global core.editor vim
Votre outil de différences
$ git config --global merge.tool vimdiff
Liste des variables configurées
$ git config --list
Fichier de configuration global
$ vi ~/.gitconfig
Création d'un projet/dossier :
$ mkdir mon_projet
$ cd mon_projet
Initialisation d'un dépôt GIT :
$ git init
C'est fait, le dépôt est initialisé, un dossier .git/ a été créé.
$ ls -l
$ ls -al
Statut :
$ git status
L'historique :
$ git log
$ git log --graph --decorate --oneline --all
$ git config --global alias.lola "log --graph --decorate --oneline --all"
$ git lola
index.html :
style.css :
$ git status
Dire à GIT de prendre en compte ces nouveaux fichiers:
$ git add .
$ git add *
$ git add index.html; git add style.css
$ git status
Commit rapide :
$ git commit -a -m "mon premier commit"
Commit pro :
$ git commit -a
Modifiez votre dernier commit :
$ git commit --amend
$ git status
$ git log
$ git diff
Avant le commitLe répertoire .git/ (créé au moment du git init)
$ find .git/objects -type f
.git/objects/0b/b3f40c0b55d604ce6382fd8c7fec1414488c07
clé SHA-1 : une somme de contrôle du contenu du fichier
$ git log
Revenir à un ancien commit de l'historique
$ git reset HEAD
$ git reset a1487727be02cb6a283a83b06b6da68
Effacer les modifications associés : Option --hard
$ git reset --hard HEAD
Travailler en parallèle sur plusieurs fonctionnalités.
Donc on crée une nouvelle branche quand une modification est :
Voir l'état des branches
$ git branch
Créer une branche
$ git branch <nom_branche>
Se déplacer entre les branches
$ git checkout <nom_branche>
Fusionner deux branches
$ git merge <nom_branche>
Supprimer une branche
$ git branch -d <nom_branche>
Mettre de côté des modifications :
$ git stash
Récupérer ces modifications :
$ git stash apply
Revenir à un état plus ancien temporairement :
$ git checkout a75ee89cd3ab6334027bc43c0cc9
En utilisant plusieurs branches :
Fusionnez le tout dans le master :
En utilisant plusieurs branches :
Fusionnez le tout dans le master :
Git gère ça pour vous :
En cas d'incertitude : Automatic merge failed; fix conflicts and then commit the result
Il suffit d'ouvrir le fichier et de choisir la bonne version
$ git mergetool
On termine par :
$ git commit -a
$ mkdir mon_projet.git
$ cd mon_projet.git
$ git init --share --bare
Dans un projet déjà existant:
$ git remote add <branche_remote> <chemin_dépot>
$ git remote rm <branche_remote>
Lister les branches remotes:
$ git remote -v
$ git push <branche_remote> <branche_locale>
Cloner un projet distant :
$ git clone <chemin_dépot>
git clone ssh://utilisateur@monserveur.com/chemin/vers/le/dépot
$ git remote -v
$ git remote add <nom_branche_remote> <dépot>
$ git remote rm <nom_branche_remote>
$ git fetch <branche_remote> <branche_locale>
$ git merge <branche_remote> <branche_locale>
Plus simple
$ git pull <branche_remote> <branche_locale>
$ git pull ; git merge
$ git log -p
$ git pull
$ git push <branche_remote> <branche_locale>
Simple et rapide
Pas très robuste
Performant
Robuste
Complet
Très Robuste
$ git tag
$ git rebase
$ git cherry-pick
$ git format-patch -1 <sha1> --stdout > <name>.patch
$ git am --signoff -k < <name>.patch
$ git-svn
$ git-ftp