cf. git cheatsheet
$ cd ~/code
$ npx ironhack_generator ironme
$ cd ironme
$ git init
$ git status
$ git add .
$ git commit -m "Mon premier commit: structure"
ironme
: https://github.com/neworigin
:
$ git remote add origin https://github.com/abernier/ironme.git
$ git push -u origin master
EloK6
dans https://github.com/abernier/ironme/settings/collaborationPendant ce temps de mon côté, je vais créer une autre branche features/about
pour développer une nouvelle page About
$ git checkout -b features/about
je bosse… puis qd la page est finie :
$ git status
$ git add <some_files>
$ git commit -m "page about ok"
J'envoie ma branche locale features/about
sur Github :
$ 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
).
features/about
dans master
Elodie termine son travail dans public/stylesheets/style.scss
:
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 :
$ git push origin master
De mon côté, je reviens sur master
:
$ git checkout master
Je rajoute du CSS qui sans le savoir encore, a déjà été ajouté par Elodie :
body {
background:yellow;
}
je commit:
$ 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.
✋Je ne peux pas pousser car je n'ai pas récupéré les modifications d'Elodie sur la branche master
$ 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.
😱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…
/* public/stylesheets/style.scss */
body {
<<<<<<< HEAD
background:red;
=======
background:yellow;
>>>>>>> master
}
$ 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
:wq
dans vim permet de sauver puis quitter.
Si vous n'aimez pas vim, vous pouvez également paramètrer VScode comme votre éditeur favori :
$ echo "export EDITOR=\"code -w\"" >~/.profile
git mergetool
Sous mac, nous pouvons configurer Filemerge afin de nous aider à résoudre les conflits :
$ sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
$ git config --global merge.tool opendiff