Accueil·Commandes du terminal

git init

git

Syntaxe

git init [-b <branch>] [<directory>]

Transforme un dossier en nouveau dépôt git ; init seul ne suit aucun fichier, il faut encore add et commit.

Options courantes

OptionSignification
-b <name>name the first branch, e.g. main
--barerepository with no working tree, for a server
--template=<dir>copy hooks and files from a template directory
--separate-git-dir=<dir>keep the .git directory somewhere else
-qprint nothing but errors

Exemples

git init

turns the current folder into a repository by creating .git

git init -b main my-app

creates my-app/ with its first branch named main

git init --separate-git-dir=~/gitdirs/app.git

keeps the .git directory elsewhere and leaves a pointer file

Ce qui embrouille, c’est qu’annuler a plusieurs formes : déplacer là où pointe une branche n’est pas ajouter un commit qui l’inverse.

Comment lire

  • Les crochets [ ] marquent une partie facultative.
  • Les points de suspension … signifient qu’on peut en mettre plusieurs.
  • Les options sont sensibles à la casse : sur certaines commandes, -r et -R ne font pas la même chose.

Questions fréquentes

Q. Que fait git init ?

Transforme un dossier en nouveau dépôt git ; init seul ne suit aucun fichier, il faut encore add et commit.

Q. Comment l’écrire ?

git init [-b <branch>] [<directory>] — les crochets marquent ce qui est facultatif.

Q. Combien d’options valent la peine ?

Il y en a 5 ici ; la liste complète est dans man git. Cette commande relève de git.

Commandes liées

page man: man git-init