Inicio·Comandos de terminal

git clone

git

Uso

git clone [--depth <n>] [-b <branch>] <url> [<directory>]

Copia un repositorio remoto con su historia; un clon con --depth 1 no trae commits antiguos ni otras ramas, y luego hace falta --unshallow.

Opciones habituales

OpciónSignificado
--depth <n>shallow copy with only the last n commits
-b <branch>check out that branch instead of the default
--single-branchfetch one branch only
--recurse-submodulesclone submodules at the same time
--filter=blob:nonepartial clone: fetch file contents on demand
-o <name>call the remote something other than origin

Ejemplos

git clone https://github.com/user/repo.git

copies the repository into repo/ and names the remote origin

git clone --depth 1 https://github.com/user/repo.git

fast copy for CI with no old history

git clone -b dev --single-branch <url>

checks out dev and fetches nothing else

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 clone?

Copia un repositorio remoto con su historia; un clon con --depth 1 no trae commits antiguos ni otras ramas, y luego hace falta --unshallow.

Q. ¿Cómo se escribe?

git clone [--depth <n>] [-b <branch>] <url> [<directory>] — los corchetes marcan lo que puedes omitir.

Q. ¿Cuántas opciones vale la pena saber?

Aquí van 6; la lista completa está en man git. Este comando está en git.

Comandos relacionados

página man: man git-clone