git - Offirmo-team/wiki GitHub Wiki
git est un outil de gestion de configuration (ou SCM). Voir aussi github, braid, SVN, Mercurial, ClearCase, CVS...
Commandes les plus utiles :
git clone --recursive ...
git status --untracked-files
git stash save --include-untracked "WIP"
CURRENT_BRANCH=`git rev-parse --abbrev-ref HEAD`; git checkout master; git pull; git checkout $CURRENT_BRANCH; git fetch origin master; git rebase origin/master
LAST_COMMIT_AUTHOR=`git log -1 --pretty=format:'%an'`
echo "LAST_COMMIT_AUTHOR:" $LAST_COMMIT_AUTHOR
CURRENT_BRANCH=`git rev-parse --abbrev-ref HEAD`
echo "CURRENT_BRANCH:" $CURRENT_BRANCH
git reset --hard HEAD^
General sur gconf (+++) http://tom.preston-werner.com/2009/05/19/the-git-parable.html
Intro graphique https://girliemac.com/blog/2017/12/26/git-purr/
Cours interactif
Tutoriels :
- https://guides.github.com/introduction/flow/
- http://www.kernel.org/pub/software/scm/git/docs/gittutorial.html
- http://justinhileman.info/article/required-git-reading/
Références :
- bon http://think-like-a-git.net/
- http://www.kernel.org/pub/software/scm/git/docs/
- http://www.kernel.org/pub/software/scm/git/docs/user-manual.html
- cheat sheet http://cdn.dzone.com/sites/all/files/refcardz/rc094-010d-git_2.pdf
Autres sources :
- http://git-scm.com/documentation
- http://polywww.in2p3.fr/~gaycken/Calice/Software/my_git_workflow.html
- http://crypto.stanford.edu/~blynn/gitmagic/
Advocacy
- http://www.peterlundgren.com/blog/on-gits-shortcomings/
- (sécurité) http://mikegerwitz.com/papers/git-horror-story.html
Attention critique !
- failles (lien à retrouver)
- https://github.com/awslabs/git-secrets
- https://github.com/commitizen/conventional-commit-types
- https://github.com/commitizen
- https://github.com/conventional-changelog
Config globale :
git config --global user.name "Offirmo"
git config --global user.email "[email protected]"
ou bien pour le dépôt en cours en fonction de l'emplacement (cf. http://www.thebuzzmedia.com/git-tip-git-config-user-name-and-user-email-for-local-not-global-config/)
git config user.name "Offirmo"
git config user.email "[email protected]"
Pour vérifier :
echo "Current git account :"
echo " `git config --get user.name` (`git config --get user.email`)"
- https://gist.github.com/jexchan/2351996
- http://superuser.com/questions/272465/using-multiple-ssh-public-keys
[remote "origin"]
url = [email protected]:Offirmo/offirmo-monorepo.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
[user]
email = [email protected]
name = Offirmo
[github]
user = Offirmo
[color]
ui = auto
[push]
default = simple
Une Configuration Git Aux Petits Oignons http://www.git-attitude.fr/2013/04/03/configuration-git
[color]
ui = auto
[user]
name = Offirmo
email = [email protected]
[github]
user = Offirmo
[push]
default = simple
[pager]
diff = diff-so-fancy | less --tabs=2 -RFX
show = diff-so-fancy | less --tabs=2 -RFX
et `npm install -g
Commencer par récupérer le dépôt, par exemple :
git clone --recursive [email protected]:Offirmo/html_tests.git
- Il peut y avoir un pb de clé SSH, voir http://help.github.com/mac-key-setup/
- --recursive cf. http://stackoverflow.com/questions/3796927/how-to-git-clone-including-submodules
Ensuite, on peut lister les branches présentes sur le serveur
git branch -r
Et choisir une branche et créez en une instance locale, cf. https://stackoverflow.com/a/48137430/587407
git fetch <origin name> <remote branch name>:<local branch name>
Et enfin, créez votre propre branche sur la base de celle-ci
git checkout <local branch name > (local branch name should the name that you given fetching)
git pull
Archi-classique : git add/rm/mv
Accepter de nombreux delete : http://stackoverflow.com/questions/492558/removing-multiple-files-from-a-git-repo-that-have-already-been-deleted-from-disk
git ls-files --deleted -z | xargs -0 git rm
Pour revenir à la dernière version commitée :
git reset
Pour restaurer un fichier unique :
git checkout --force <fichier>
C'est très casse-pieds... ...
git push
Si vous voulez envoyer votre nouvelle branche 'toto' sur le repo, faites ;
git push origin toto
Pour développer, vous n'avez besoin que de la branche de dev courante. Il faut la récupérer depuis le repo maître.
git checkout -b v0_dev origin/v0_dev
- Se placer dans la branche de dev
git checkout v0_dev
- Récupérer les dernières modifs
git pull
- partir en branche dédiée
git checkout -b v0_dev_YEJ
- Tout mettre au propre, et vérifier que git status indique
nothing to commit (working directory clean)
- Repasser en branche de dev
git checkout v0_dev
- Récupérer la dernière version (au cas où)
git pull
- merger
git merge v0_dev_YEJ
- Pousser
git push
http://aralbalkan.com/1905/ http://git-scm.com/book/en/Git-Basics-Tagging
git tag -a v0.9.1 -m 'version 0.9.1'
git push --tags
effacer tous les fichiers ignorés: https://stackoverflow.com/a/42185640/587407
git clean -ffdx -n. <-- -n = show but don't do it
git clean -ffdx
untracked: https://koukia.ca/how-to-remove-local-untracked-files-from-the-current-git-branch-571c6ce9b6b1
https://www.kernel.org/pub/software/scm/git/docs/git-stash.html
git stash
git stash pop
git stash save --include-untracked "un gros boulot"
git stash apply
git stash list
git stash drop <...>
- http://stackoverflow.com/questions/273695/git-branch-naming-best-practices
- une opinion http://www.guyroutledge.co.uk/blog/git-branch-naming-conventions/
- http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
- +++ https://github.com/angular/angular.js/blob/master/CONTRIBUTING.md#-git-commit-guidelines
https://enkipro.com//insight/56c47fef0b57870600f41d6a
- https://robots.thoughtbot.com/autosquashing-git-commits
- https://robots.thoughtbot.com/git-interactive-rebase-squash-amend-rewriting-history
On peut activer de la couleur dans le résultat des commandes git : http://scie.nti.st/2007/5/2/colors-in-git
- http://www.kernel.org/pub/software/scm/git/docs/git-submodule.html
- http://www.kernel.org/pub/software/scm/git/docs/user-manual.html#submodules
- http://git-scm.com/book/en/Git-Tools-Submodules
Ajouter un nouveau sous-module :
- lancer la commande d'ajout de sous-module, ex. :
git submodule add [email protected]:Offirmo/generic_store.js.git incubator/generic_store.js
- faire
git status
-> le dossier racine du sous-module apparait comme "new" - commiter
- c'est bon, ne jamais rien mettre dans le dossier (pas besoin de .gitkeep), laisser submodule s'en charger.
Récupérer les sous-modules :
- se fait auto si on utilise
git clone --recursive
- Et si on a oublié, alors
git submodules init
git submodules update
Supprimer un sous module ? Ce n'a pas l'air d'être prévu dans git submodule. Il faut donc le faire à la main (gore) : http://www.hackido.com/2009/01/quick-tip-remove-git-submodule.html et https://git.wiki.kernel.org/index.php/GitSubmoduleTutorial
- effacer la référence au sous-module dans .gitmodules
- effacer la référence au sous-module dans .git/config
- effacer les infos git du sous-module dans .git/modules
- effacer le dossier du sous-module avec git rm --cached
- http://www.git-attitude.fr/2014/05/04/bien-utiliser-git-merge-et-rebase/
- http://nvie.com/posts/a-successful-git-branching-model/ + http://justinhileman.info/article/changing-history/
http://www.kernel.org/pub/software/scm/git/docs/git-branch.html
- partir en branche
git branch crazy-experiment
- liste des branches locales (rappel)
git branch
- liste des branches distantes (rappel)
git branch -r
- Passer en branche existante
git checkout <branch>
- destruction d'une branche
git branch -d toto
- récupérer localement une branche distante
git branch --track origin/toto
- Simuler un merge : pas encore trouvé comment faire mais on peut au moins dire de ne pas merger si pas fast forward :
git merge branche_xyz --ff-only
- github : merger depuis un fork ou ancêtre
- http://stackoverflow.com/questions/1123344/merging-between-forks-in-github
- http://stackoverflow.com/questions/1405030/using-git-how-can-i-selectively-pull-merge-changes-from-anothers-fork
git remote prune origin https://coderwall.com/p/eis0ba/remove-a-thousand-stale-remote-branches-on-git
git branch --merged | grep -v "^\*\\|main|master" | xargs -n 1 git branch -d http://stevenharman.net/git-clean-delete-already-merged-branches
git gc
nettoie et optimise quelques trucs. Par contre attention à
git clean
car celui-là efface les fichiers non gérés en conf.
http://www.producthunt.com/anujadhiya/collections/all-things-github
- docker wf automation https://shipway.io/
- stars https://app.astralapp.com/dashboard
https://medium.com/@porteneuve/30-git-cli-options-you-should-know-about-15423e8771df
Il peut y avoir un pb de clé SSH, voir http://help.github.com/mac-key-setup/
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
git config --global user.name "Your Name"
git config --global user.email [email protected]
If the identity used for this commit is wrong, you can fix it with:
git commit --amend --author='Your Name <[email protected]>'
Vérifier ses infos :
git config --get user.name
git config --get user.email
git + mercurial : https://sites.google.com/a/waveprotocol.org/wave-protocol/code/tutorials/git-mercurial-howto
Il y a des commandes git peu documentées. Voir la liste complète ici :http://www.kernel.org/pub/software/scm/git/docs/