---
tags: ironhack
---
# github workflow demo (conflits)
cf. [git cheatsheet](https://hackmd.io/-1mXub_GTn6trkg0v5dW2Q)
## Création du projet
```shell
$ cd ~/code
$ npx ironhack_generator ironme
$ cd ironme
```
## Activation versionning + 1er commit
```shell
$ git init
```
```
$ git status
$ git add .
$ git commit -m "Mon premier commit: structure"
```
## Création du repo github
- Je crée un nouveau repo github `ironme` : https://github.com/new
- J'ajoute le remote `origin` :
```shell
$ git remote add origin https://github.com/abernier/ironme.git
```
- J'envoie mon 1er commit :
```shell
$ git push -u origin master
```
## Elo, tu t'occupes du CSS ?
- ajouter `EloK6` dans https://github.com/abernier/ironme/settings/collaboration
- Envoyer le lien d'invit à Elodie et attendre qu'elle accepte => la montrer ensuite dans les collaborateurs
- Elodie peut maintenant contribuer au projet Github : elle clone le répo sur sa machine et commencer à bosser...
## About page
Pendant ce temps de mon côté, je vais créer une autre branche `features/about` pour développer une nouvelle page `About`
```shell
$ git checkout -b features/about
```
je bosse... puis qd la page est finie :
```shell
$ git status
$ git add <some_files>
$ git commit -m "page about ok"
```
J'envoie ma branche locale `features/about` sur Github :
```shell
$ git push -u origin features/about
```
J'informe Elodie que ma branche est poussée et qu'elle pourra quand elle voudra l'intégrer à sa branche (`master`).
## Merge de `features/about` dans `master`
Elodie termine son travail dans `public/stylesheets/style.scss`:
```sass
body {
background:black;
}
```
C'est beau, elle commit :
```
$ git status
$ git add public/stylesheets/style.scss
$ git commit -m "Styling homepage finito"
```
Maintenant qu'Elodie n'a plus de modification en cours, elle va s'occuper d'intégrer ma branche :
```
$ git pull origin features/about
```
Si pas de conflit : ok, elle doit maintenant voir la page about.
---
⚠️ Elle n'oublie pas d'envoyer sa version mergée de master :
```shell
$ git push origin master
```
## Conflits
De mon côté, je reviens sur `master`:
```shell
$ git checkout master
```
Je rajoute du CSS qui sans le savoir encore, a déjà été ajouté par Elodie :
```css
body {
background:yellow;
}
```
je commit:
```shell
$ git add public/stylesheets/style.scss
$ git commit -m "yellow is the new black"
$ git push origin master
To https://github.com/abernier/ironme.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/abernier/ironme.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
```
:::warning
✋Je ne peux pas pousser car je n'ai pas récupéré les modifications d'Elodie sur la branche `master`
:::
```shell
$ git pull origin master
From https://github.com/abernier/ironme.git
* branch master -> FETCH_HEAD
Auto-merging public/stylesheets/style.scss
CONFLICT (content): Merge conflict in public/stylesheets/style.scss
Automatic merge failed; fix conflicts and then commit the result.
```
:::danger
😱Conflit : Nous avons tous les 2 modifié la même ligne de code : git ne sait pas quelle version choisir. Nous allons devoir résoudre ce conflit nous-même pour décider...
:::
```css
/* public/stylesheets/style.scss */
body {
<<<<<<< HEAD
background:red;
=======
background:yellow;
>>>>>>> master
}
```
```shell
$ git status
Unmerged paths:
(use "git add <file>..." to mark resolution)
both modified: public/stylesheets/style.scss
```
Une fois résolu :
```
$ git add index.css
$ git commit
```
:::info
`:wq` dans vim permet de sauver puis quitter.
:::
:::info
Si vous n'aimez pas vim, vous pouvez également paramètrer VScode comme votre éditeur favori :
```shell
$ echo "export EDITOR=\"code -w\"" >~/.profile
```
:::
### `git mergetool`
Sous mac, nous pouvons configurer Filemerge afin de nous aider à résoudre les conflits :
```shell
$ sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
$ git config --global merge.tool opendiff
```

cf. https://gist.github.com/kylefox/4512777