Github
Github
Qué es Github
A brief introduction to Git for beginners | GitHub Banco Interamericano de Desarollo Code4Dev: ¿Cómo optimizar tu repositorio de código abierto con Git y GitHub?Introduction to GitHub
- Introduction to GitHub. Link
Recursos de ayuda
Comandos básicos de Git
Configuración inicial
#Instalarlo con Homebrew
instalar el GitHub CLI primero. Voy a instalarlo usando Homebrew.
`brew install gh`
`gh auth login` para autenticarse
# Configurar nombre y email
git config --global user.name "Tu Nombre"
git config --global user.email "tu@email.com"
# Ver configuración
git config --listCrear y clonar repositorios
# Inicializar repositorio
git init
# Clonar repositorio
git clone https://github.com/usuario/repositorio.git
# Clonar con nombre específico
git clone https://github.com/usuario/repositorio.git mi-proyectoComandos esenciales
# Ver estado
git status
# Agregar archivos
git add archivo.txt
git add . # Agregar todos
# Hacer commit
git commit -m "Mensaje descriptivo"
# Ver historial
git log
git log --oneline --graphTrabajar con remotos
# Ver remotos
git remote -v
# Agregar remoto
git remote add origin https://github.com/usuario/repo.git
# Push
git push origin main
# Pull
git pull origin mainNivel intermedio
Branching (Ramificación)
Crear y cambiar ramas
# Crear rama
git branch nombre-rama
# Cambiar a rama
git checkout nombre-rama
# Crear y cambiar en un comando
git checkout -b nueva-rama
# Cambiar de rama (forma moderna)
git switch nombre-rama
git switch -c nueva-rama # Crear y cambiarFusionar ramas
# Fusionar rama en la actual
git merge nombre-rama
# Fusionar con squash (combinar commits)
git merge --squash nombre-rama
# Abortar merge conflictivo
git merge --abortEliminar ramas
# Eliminar rama local
git branch -d nombre-rama # Solo si está fusionada
git branch -D nombre-rama # Forzar eliminación
# Eliminar rama remota
git push origin --delete nombre-ramaManejo de conflictos
# Ver archivos con conflictos
git status
# Después de resolver manualmente
git add archivo-resuelto.txt
git commit -m "Resolver conflicto"
# Usar herramienta de merge
git mergetoolRebase interactivo
# Rebase interactivo de últimos 3 commits
git rebase -i HEAD~3
# Rebase sobre otra rama
git rebase main
# Continuar después de resolver conflictos
git rebase --continue
# Abortar rebase
git rebase --abortStash (Guardar cambios temporalmente)
# Guardar cambios
git stash
git stash save "Mensaje descriptivo"
# Ver stashes guardados
git stash list
# Aplicar último stash
git stash apply
git stash pop # Aplicar y eliminar
# Aplicar stash específico
git stash apply stash@{2}
# Eliminar stash
git stash drop stash@{0}
git stash clear # Eliminar todosCherry-pick (Seleccionar commits específicos)
# Aplicar commit específico a rama actual
git cherry-pick abc123
# Cherry-pick múltiples commits
git cherry-pick abc123 def456
# Cherry-pick sin hacer commit automático
git cherry-pick -n abc123Comandos útiles avanzados
Git reflog (Recuperar commits)
# Ver historial de referencias
git reflog
# Recuperar commit perdido
git checkout abc123
git reset --hard abc123Git diff avanzado
# Diferencias entre ramas
git diff main..feature
# Diferencias de archivos específicos
git diff HEAD -- archivo.txt
# Diferencias con estadísticas
git diff --statGit reset y revert
# Deshacer último commit (mantener cambios)
git reset --soft HEAD~1
# Deshacer último commit (descartar cambios)
git reset --hard HEAD~1
# Revertir commit creando nuevo commit
git revert abc123GitHub CLI (gh)
# Instalar GitHub CLI
# macOS: brew install gh
# Windows: winget install GitHub.cli
# Login
gh auth login
# Crear repositorio
gh repo create nombre-repo --public
# Crear PR
gh pr create --title "Nueva feature" --body "Descripción"
# Ver PRs
gh pr list
gh pr view 123
# Clonar repos
gh repo clone usuario/repositorioGitHub Actions básico
# .github/workflows/ci.yml
name: CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
run: |
pip install -r requirements.txt
- name: Run tests
run: pytestTrabajo colaborativo
Pull Requests
# Crear rama para feature
git checkout -b feature/nueva-funcionalidad
# Hacer cambios y commits
git add .
git commit -m "Agregar nueva funcionalidad"
# Push de la rama
git push origin feature/nueva-funcionalidad
# Luego crear PR en GitHub web o con gh cli
gh pr createCode Review
# Ver cambios de PR
gh pr checkout 123
gh pr diff 123
# Comentar en PR
gh pr comment 123 --body "Se ve bien!"
# Aprobar PR
gh pr review 123 --approve
# Mergear PR
gh pr merge 123.gitignore avanzado
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
env/
venv/
# IDEs
.vscode/
.idea/
*.swp
# OS
.DS_Store
Thumbs.db
# Logs
*.log
logs/
# Environment variables
.env
.env.local
# Build
dist/
build/
*.egg-info/
GitHub Pages
# Crear rama gh-pages
git checkout --orphan gh-pages
# Agregar contenido
git add .
git commit -m "Initial GitHub Pages"
# Push
git push origin gh-pages
# Configurar en Settings → PagesVideos tutoriales recomendados
Nivel básico
Nivel intermedio
GitHub específico
Proyectos destacados en GitHub
Recursos de aprendizaje
Herramientas Git/GitHub
GitHub Actions
Automatización y CI/CD
Perfiles y documentación
- github-profile-readme-generator - Generador de README perfil Link
- awesome-readme - Ejemplos de READMEs increíbles Link
- shields - Badges para repositorios Link