Proceso de Subida de un Archivo en Git y Errores Comunes

·

2 min read

Imagen tomada de fuente: https://geekebrains.com/code-brains/git

Paso a Paso de la Ejecución de Comandos en Git

1. Inicializar un Repositorio

git init

Salida esperada:

Initialized empty Git repository in /ruta/del/repositorio/.git/

2. Ver el Estado del Repositorio

git status

Salida esperada:

On branch main
No commits yet
Untracked files:
  (use "git add <file>..." to include in what will be committed)
    git-helper.sh

3. Agregar Archivos al Área de Staging

git add git-helper.sh

Error común:

fatal: empty string is not a valid pathspec. please use . instead if you meant to match all paths

Solución: Usar git add . para agregar todos los archivos.

Salida esperada tras corregir:

git status
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
    new file:   git-helper.sh

4. Hacer un Commit

git commit -m "Subiendo script de ayuda de git"

Salida esperada:

[main 87af9f3] Subiendo script de ayuda de git
 Committer: user <user@example.com>
 1 file changed, 142 insertions(+)
 create mode 100755 git-helper.sh

Error posible:

Please tell me who you are

Solución: Configurar Git con:

git config --global user.name "Tu Nombre"
git config --global user.email "tuemail@example.com"

5. Subir Cambios al Repositorio Remoto

git push origin main

Salida esperada:

Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), done.
To github.com:usuario/repositorio.git
   8bf1f34..87af9f3  main -> main

Error posible:

Your branch is ahead of 'origin/main' by 1 commit.

Solución: Usar git push origin main para sincronizar los cambios.


Documentación git

Aquí hay documentación sobre git: https://git-scm.com/doc


Simuladores para Practicar Git

Para practicar y reforzar tus conocimientos, te recomiendo los siguientes simuladores interactivos:

  • Learn Git Branching: Una aplicación web que simula un repositorio Git en tu navegador, permitiéndote experimentar con diferentes comandos y visualizar sus efectos en tiempo real.

    learngitbranching.js.org

  • Oh My Git!: Un juego de código abierto que te enseña los conceptos básicos de Git de manera divertida y práctica. Disponible para Linux, macOS y Windows.

    ohmygit.org

Estos recursos te permitirán visualizar y practicar el flujo de trabajo en Git de manera efectiva.