Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente Prochaine révisionLes deux révisions suivantes | ||
technique:git:git_avancees [2019/04/13 15:23] – créée francoisa | technique:git:git_avancees [2020/04/26 02:50] – francoisa | ||
---|---|---|---|
Ligne 7: | Ligne 7: | ||
On crée une nouvelle branche au projet, à partir de la branche master | On crée une nouvelle branche au projet, à partir de la branche master | ||
- | git branche | + | < |
+ | git branch | ||
+ | |||
+ | </ | ||
On passe sur la branche nouvellebranche | On passe sur la branche nouvellebranche | ||
+ | < | ||
git checkout nouvellebranche | git checkout nouvellebranche | ||
+ | |||
+ | </ | ||
+ | |||
+ | ou plus directement : | ||
+ | |||
+ | < | ||
+ | git checkout -b nouvellebranche | ||
+ | |||
+ | </ | ||
On peut faire des commits (git add & git commit) sur cette branche. On peut aussi repasser sur la branche principale et en faire d' | On peut faire des commits (git add & git commit) sur cette branche. On peut aussi repasser sur la branche principale et en faire d' | ||
+ | < | ||
git checkout master | git checkout master | ||
+ | |||
+ | </ | ||
+ | |||
+ | Il est aussi possible de venir se placer sur un commit, une branche ou un tag précédent : | ||
+ | |||
+ | < | ||
+ | git checkout nomcommit | ||
+ | git checkout vieillebranche | ||
+ | git checkout nomtag | ||
+ | |||
+ | </ | ||
+ | |||
+ | (Voir git checkout -h) | ||
===== 2. Fusion de branche (merge) ===== | ===== 2. Fusion de branche (merge) ===== | ||
Ligne 23: | Ligne 50: | ||
< | < | ||
git checkout master | git checkout master | ||
+ | |||
</ | </ | ||
Ligne 29: | Ligne 57: | ||
< | < | ||
git merge nouvellebranche | git merge nouvellebranche | ||
+ | |||
</ | </ | ||
Ligne 34: | Ligne 63: | ||
< | < | ||
- | git branch -d nouvellebranche | + | git branch -d nouvellebranche |
+ | ou | ||
+ | git branch -D nouvellebranche # si pas fusionnée | ||
</ | </ | ||
+ | |||
+ | ===== Gestion de conflits ===== | ||
+ | |||
+ | En cas de merge conflictuel, | ||
+ | |||
+ | Il faut éditer les fichiers en conflit et finir avec un : | ||
+ | |||
+ | < | ||
+ | git add fichiers_en_conflit | ||
+ | git commit | ||
+ | |||
+ | </ | ||
+ | |||
+ | Il est possible d' | ||
+ | |||
+ | < | ||
+ | git mergetool fichier_en_conflit | ||
+ | |||
+ | </ | ||
+ | |||
+ | Il est possible de merger sans créer de nouveau commit : | ||
+ | |||
+ | < | ||
+ | git merge --no-commit nouvellebranche | ||
+ | |||
+ | </ | ||
+ | |||
+ | Puis modifier/ | ||
+ | |||
+ | Il est alors aussi possible d' | ||
+ | |||
+ | < | ||
+ | git merge --abort | ||
+ | |||
+ | </ | ||
+ | |||
+ | ===== Travail collaboratif ===== | ||
+ | |||
+ | Récupérer un dépot distant avec : | ||
+ | |||
+ | < | ||
+ | git clone url_distant | ||
+ | |||
+ | </ | ||
+ | |||
+ | Dans ce cas, l' | ||
+ | |||
+ | git fetch permet de récupérer les branches distantes. Attention, git pull <⇒ git fetch | ||
+ | |||
+ | < | ||
+ | git pull # récupère les sources et merge les différences | ||
+ | git fetch # récupère les sources sans fusionner | ||
+ | |||
+ | </ | ||
+ | |||
+ | git pull = git fetch + git merge FETCH_HEAD | ||
+ | |||
+ | Pour voir les différences avec le dépot distant : | ||
+ | |||
+ | < | ||
+ | git remote -v | ||
+ | git branch -r # pour voir les branches distantes connues localement | ||
+ | git branch -vv # si la branche loclae est trackée | ||
+ | |||
+ | </ | ||
+ | |||
+ | ===== Ajout d'un dépot supplémentaire distant ===== | ||
+ | |||
+ | < | ||
+ | git remote add nomchoisi urldepot.git | ||
+ | |||
+ | git fetch nomchoisi | ||
+ | |||
+ | </ | ||
+ | |||
+ | Et pour mettre à jour le dépot local vers ce dépot distant : | ||
+ | |||
+ | < | ||
+ | git push -u nomchoisi master | ||
+ | |||
+ | </ | ||
+ | |||
+ | Attention, il faudra metre à jour les 2 dépots de manière manuelle. Par exemple : | ||
+ | |||
+ | < | ||
+ | git push heroku master | ||
+ | |||
+ | git push -u nomchoisi master | ||
+ | |||
+ | </ | ||
+ | ===== Gestion d'un dépot avec authentification par clef SSH ===== | ||
+ | |||
+ | 1) Ajouter sa clef SSH publique dans son profil du dépot distant (github, framagit...) | ||
+ | |||
+ | 2) Définir par défaut l' | ||
+ | < | ||
+ | Host github.com | ||
+ | | ||
+ | |||
+ | </ | ||
+ | |||
+ | 3) définir pour le dépot git local que l' | ||
+ | < | ||
+ | [remote " | ||
+ | url = ssh:// | ||
+ | |||
+ | </ | ||
+ | |||
+ | Et c'est tout. Au prochain '' | ||
+ | |||