git init
git
Uso
git init [-b <branch>] [<directory>]Convierte una carpeta en un repositorio git nuevo; init por sí solo no rastrea nada, aún hacen falta add y commit.
Opciones habituales
| Opción | Significado |
|---|---|
| -b <name> | name the first branch, e.g. main |
| --bare | repository 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 |
| -q | print nothing but errors |
Ejemplos
git initturns the current folder into a repository by creating .git
git init -b main my-appcreates my-app/ with its first branch named main
git init --separate-git-dir=~/gitdirs/app.gitkeeps the .git directory elsewhere and leaves a pointer file
Lo confuso es que deshacer tiene varias formas: mover a dónde apunta una rama no es lo mismo que añadir un commit que la revierte.
Cómo leerlo
- Los corchetes [ ] marcan una parte que puedes omitir.
- Los puntos suspensivos … indican que puedes poner varios.
- Las opciones distinguen mayúsculas: en algunos comandos -r y -R no hacen lo mismo.
Preguntas
Q. ¿Qué hace git init?
Convierte una carpeta en un repositorio git nuevo; init por sí solo no rastrea nada, aún hacen falta add y commit.
Q. ¿Cómo se escribe?
git init [-b <branch>] [<directory>] — los corchetes marcan lo que puedes omitir.
Q. ¿Cuántas opciones vale la pena saber?
Aquí van 5; la lista completa está en man git. Este comando está en git.
Comandos relacionados
página man: man git-init