guias update ia
This commit is contained in:
+196
-274
@@ -1,131 +1,131 @@
|
||||
**AYUDA GIT**
|
||||
=============
|
||||
|
||||
**https://git-scm.com/**
|
||||
|
||||
-------------------
|
||||
|
||||
**CONFIGURAR GIT. CONFIGURACION LOCAL**
|
||||
```bash
|
||||
git config --global user.name "Tu Nombre"
|
||||
# Guía de Git y Gitea
|
||||
|
||||
Git es un sistema de control de versiones para guardar cambios, colaborar y mantener un historial de desarrollo.
|
||||
|
||||
## 1. Configuración inicial
|
||||
|
||||
```bash
|
||||
git config --global user.name "Tu Nombre"
|
||||
git config --global user.email "[email protected]"
|
||||
```
|
||||
|
||||
| Comando | Acción |
|
||||
|:------------------------- |:----------------------------------------------|
|
||||
| git config --global init.defaultBranch main|Establecer main como rama por defecto en configuracion global
|
||||
| git config --global --list|muestra datos configuracion global del repositorio |
|
||||
| git config --list | Muestra datos configuración global (usuario, email, etc.) |
|
||||
| git config --global core.autocrlf true |Uso en windows |
|
||||
| git config --global core.autocrlf input | Uso en Mac/Linux |
|
||||
|
||||
|
||||
-------------------
|
||||
|
||||
**CREAR REPOSITORIO EN GITHUB**
|
||||
Inicia sesión en tu cuenta de GitHub.
|
||||
Haz clic en el botón "New" en la esquina superior derecha.
|
||||
Asigna un nombre a tu repositorio, elige la visibilidad (público o privado) y haz clic en "Create repository".
|
||||
cd ruta/de/tu/carpeta
|
||||
GitHub, por defecto, crea repositorios con la rama main
|
||||
|
||||
-------------------
|
||||
**COMANDO GIT BASICOS**
|
||||
Ver la configuración:
|
||||
|
||||
```bash
|
||||
git config --global --list
|
||||
git config --list
|
||||
```
|
||||
|
||||
| Comando | Acción |
|
||||
|:------------------------- |:----------------------------------------------|
|
||||
| Git init | Inicia un repositorio, crea una carpeta. oculta .git donde Git almacenará los cambios. |
|
||||
| git add . | Agrega los archivos al área de preparación (staging):|
|
||||
| git add nombre-del-archivo | agregar uno específico |
|
||||
| git commit -m "mensanje descriptivo" | Guardar los cambios, registra los cambios en el historial de Git |
|
||||
| git commit -am "mensaje" | Agrega archivos modificados y hace el commit (no para archivos nuevos) |
|
||||
| git rm --cached archivo.txt | quitar archivo del indice para evitar seguimiento por git |
|
||||
| git add . && git commit -m "mensaje"| Agrega archivo nuevos y hace commit|
|
||||
| git log | Ver el Historial de Cambios, lista de commits|
|
||||
| git log --oneline --graph --all| resumen compacto|
|
||||
| git reset nombre_archivo / git checkout -- nombre_archivo| Deshacer los cambios, quitar archivos del area de preparacion. (antes de commit)|
|
||||
| git reset --soft HEAD~1| Deshacer el último commit|
|
||||
| git reset --hard HEAD~1 | Eliminar completamente el último commit|
|
||||
| git rm archivo| Eliminar del stage|
|
||||
| git count-objects -vH | Saber cuanto pesa el historial|
|
||||
| git mv | Cambiar nombre del stage|
|
||||
| .gitignore |Ignorar archivos para seguimiento de Git|
|
||||
Crear archivo .gitignore / editar archivos a ignorar
|
||||
git add .gitignore / git commit -m "commit git ignore"
|
||||
Configuraciones útiles:
|
||||
|
||||
|
||||
-------------------
|
||||
|
||||
**PULL / PUSH**
|
||||
```bash
|
||||
git config --global init.defaultBranch main
|
||||
git config --global core.autocrlf true # Windows
|
||||
git config --global core.autocrlf input # macOS/Linux
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
| Comando | Acción |
|
||||
|:------------------------- |:----------------------------------------------|
|
||||
| Git init | Inicia un repositorio, crea una carpeta. |
|
||||
| git push -u origin main| Subir los archivos a repositorio remoto (GitHub, gitlab, etc, confirmar que se esta en la rama en git)|
|
||||
| git push -u origin master| subir archivos si la rama local se llama master|
|
||||
| git push -u origin master:main| Sube a remoto a la rama main el repositorio local de rama master |
|
||||
| git push --force origin main | Sobreescribe el remoto, enviando los cambios del local cuando dice que el remoto no coincide.|
|
||||
| git status status-s | Ver el Estado del Repositorio / -s info resumida |
|
||||
| git pull origin main --rebase| Sincroniza el local con el remoto (cambios en remoto que no hay que perder)|
|
||||
| git push --force origin main | Sobreescribir repo remoto (el remoto tiene cambios que no me interesan y se pueden sobreescribir con la version de local)|
|
||||
## 2. Crear repositorio en GitHub
|
||||
|
||||
```bash
|
||||
cd ruta/de/tu/carpeta
|
||||
git init
|
||||
git add .
|
||||
git commit -m "Primer commit"
|
||||
git branch -M main
|
||||
git remote add origin https://github.com/tu-usuario/tu-repositorio.git
|
||||
git push -u origin main
|
||||
```
|
||||
|
||||
|
||||
-------------------
|
||||
|
||||
**REPOSITORIOS**
|
||||
---
|
||||
|
||||
| Comando | Acción |
|
||||
|:------------------------- |:----------------------------------------------|
|
||||
| git remote add origin NUEVA_URL | Agregar un nuevo remoto |
|
||||
| git remote -v | Ver el remoto actual|
|
||||
| git remote set-url origin NUEVA_URL | Cambiar el remoto|
|
||||
| git remote remove origin | Eliminar el remoto|
|
||||
| git remote add origin https://github.com/tu-usuario/tu-repositorio.git | Conectar el repositorio local con GitHub git remote add origin URL_DEL_REPO Añadir repositorio remoto (github, gitlab, etc...)|
|
||||
| git pull origin main| Obtener Cambios del Repositorio Remoto (actualizar el codigo)|
|
||||
| git pull --rebase origin main| Trae cambios (archivos) del remoto sin afectar al local. Despues add y commit.|
|
||||
| git clone URL_DEL_REPO| Clonar un Repositorio|
|
||||
|
||||
|
||||
|
||||
-------------------
|
||||
|
||||
**RAMAS**
|
||||
## 3. Comandos básicos
|
||||
|
||||
| Comando | Acción |
|
||||
|:------------------------- |:----------------------------------------------|
|
||||
| git branch | Agregar un nuevo remoto |
|
||||
| git branch -a | Ver todas las ramas, incluyendo las remotas|
|
||||
| git branch nueva-rama|Crear una nueva rama (no te situa en la rama creada)|
|
||||
| git checkout nueva-rama|Cambiar a una rama |
|
||||
| git switch nueva-rama|Cambiar a una rama (nuevo sistema recomendado) |
|
||||
| git checkout -b nueva-rama|Crear rama y cambiar a ella automaticamente|
|
||||
| git switch -c nueva-rama|Crear rama e ir a ella, nuevo comando |
|
||||
| git merge rama|Fusionar rama, integrar cambios (previamente situarse en la rama main/master)
|
||||
Si hay conflictos, Git te pedirá que los resuelvas manualmente antes de confirmar la fusión. |
|
||||
| git branch -d nueva-rama|Eliminar una rama local (usa -D si la rama no ha sido fusionada y quieres forzar su eliminación). |
|
||||
|git push origin --delete rama |Eliminar una rama remota:|
|
||||
|git fetch|Trae rama a tu repositorio local git checkout nombre-de-la-rama|
|
||||
|git pull origin nombre-de-la-rama |Trae rama a tu repositorio local con un solo comando|
|
||||
|git branch -m master main |cambiar nombre de rama (cambia nombre rama master a main, para GitHub) |
|
||||
|git branch -d nombre-de-la-rama|Eliminar una rama localmente |
|
||||
|git branch -m master main |Renombrar rama máster a main |
|
||||
|
||||
|
||||
-------------------
|
||||
|
||||
**Resumen**
|
||||
Usa ramas para desarrollar nuevas funciones sin afectar main.
|
||||
Cambia entre ramas con git switch o git checkout.
|
||||
Fusiona cambios con git merge.
|
||||
Borra ramas innecesarias con git branch -d.
|
||||
Sube ramas con git push -u origin rama.
|
||||
|
||||
-------------------
|
||||
| Comando | Acción |
|
||||
|---|---|
|
||||
| `git init` | Inicia un repositorio |
|
||||
| `git add archivo` | Añade archivos al staging |
|
||||
| `git add .` | Añade todos los cambios |
|
||||
| `git commit -m "mensaje"` | Guarda cambios |
|
||||
| `git commit -am "mensaje"` | Commit de archivos ya rastreados |
|
||||
| `git status` | Muestra estado del repositorio |
|
||||
| `git log` | Muestra historial |
|
||||
| `git log --oneline --graph --all` | Vista compacta |
|
||||
| `git rm --cached archivo.txt` | Quita de seguimiento |
|
||||
| `git mv origen destino` | Renombra o mueve archivo |
|
||||
|
||||
---
|
||||
|
||||
## 4. Pull y push
|
||||
|
||||
```bash
|
||||
git pull origin main
|
||||
git push -u origin main
|
||||
```
|
||||
|
||||
Otras opciones:
|
||||
|
||||
```bash
|
||||
git push -u origin master
|
||||
git push -u origin master:main
|
||||
git push --force origin main
|
||||
git pull origin main --rebase
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 5. Remotos
|
||||
|
||||
```bash
|
||||
git remote add origin https://github.com/tu-usuario/tu-repositorio.git
|
||||
git remote -v
|
||||
git remote set-url origin NUEVA_URL
|
||||
git remote remove origin
|
||||
git clone URL_DEL_REPO
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 6. Ramas
|
||||
|
||||
```bash
|
||||
git branch
|
||||
git branch -a
|
||||
git branch nueva-rama
|
||||
git checkout nueva-rama
|
||||
git switch nueva-rama
|
||||
git checkout -b nueva-rama
|
||||
git switch -c nueva-rama
|
||||
git merge rama
|
||||
git branch -d nueva-rama
|
||||
git branch -D nueva-rama
|
||||
git push origin --delete rama
|
||||
```
|
||||
|
||||
Renombrar rama:
|
||||
|
||||
```bash
|
||||
git branch -m master main
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 7. Deshacer cambios
|
||||
|
||||
```bash
|
||||
git reset nombre_archivo
|
||||
git checkout -- nombre_archivo
|
||||
git reset --soft HEAD~1
|
||||
git reset --hard HEAD~1
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 8. `.gitignore`
|
||||
|
||||
Ejemplo:
|
||||
|
||||
**.gitignore**
|
||||
```bash
|
||||
# Archivo concreto
|
||||
.env
|
||||
@@ -136,178 +136,100 @@ Sube ramas con git push -u origin rama.
|
||||
# Carpeta completa
|
||||
node_modules/
|
||||
|
||||
# Carpeta de compilación
|
||||
dist/
|
||||
|
||||
# Archivos temporales
|
||||
# Temporales
|
||||
*.tmp
|
||||
```
|
||||
|
||||
**GITHUB TOKEN**
|
||||
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
|
||||
|
||||
clonar un repositorio privado utilizando el toquen
|
||||
git clone https://<TOKEN>@github.com/codibytex/python_scripts.git
|
||||
|
||||
ejemplo practico con el token generado:
|
||||
git clone https://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@github.com/codibytex/python_scripts.git
|
||||
|
||||
https://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@github.com/codibytex/detenpol.git
|
||||
|
||||
echo "# fusionar_comprimir_pdf" >> README.md
|
||||
git init
|
||||
git add README.md
|
||||
git commit -m "first commit"
|
||||
git branch -M main
|
||||
git remote add origin https://github.com/codibytex/fusionar_comprimir_pdf.git
|
||||
git push -u origin main
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
**AYUDA GITEA**
|
||||
=============
|
||||
|
||||
**Gitea en docker**
|
||||
|
||||
**backup version 1**
|
||||
```
|
||||
bash
|
||||
docker exec -it gitea bash
|
||||
gitea dump
|
||||
```
|
||||
|
||||
Esto generará un archivo tipo:
|
||||
`gitea-dump-YYYY-MM-DD.zip`
|
||||
|
||||
Normalmente se guarda en:
|
||||
`/data`
|
||||
|
||||
Copia el backup al host
|
||||
`docker cp gitea:/data/gitea-dump-YYYY-MM-DD.zip .`
|
||||
|
||||
**backup version 2**
|
||||
Aplicarlo:
|
||||
|
||||
```bash
|
||||
git add .gitignore
|
||||
git commit -m "Agregar .gitignore"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 9. Token de GitHub
|
||||
|
||||
```bash
|
||||
git clone https://<TOKEN>@github.com/usuario/repositorio.git
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 10. Gitea con Docker
|
||||
|
||||
### Backup versión 1
|
||||
|
||||
```bash
|
||||
docker exec -it gitea bash
|
||||
gitea dump
|
||||
```
|
||||
|
||||
Genera un archivo como:
|
||||
|
||||
```text
|
||||
gitea-dump-YYYY-MM-DD.zip
|
||||
```
|
||||
|
||||
Copiarlo al host:
|
||||
|
||||
```bash
|
||||
docker cp gitea:/data/gitea-dump-YYYY-MM-DD.zip .
|
||||
```
|
||||
|
||||
### Backup versión 2
|
||||
|
||||
```bash
|
||||
docker exec -u 1000:1000 gitea rm -f /data/git/gitea-backup.zip
|
||||
|
||||
Borrar backup anterior dentro de gitea
|
||||
```docker exec -u 1000:1000 gitea rm -f /data/git/gitea-backup.zip
|
||||
#Comprueba:
|
||||
docker exec gitea ls -lh /data/git/gitea-backup.zip
|
||||
#Debería responder que no existe.
|
||||
#Ahora nuevo backup:
|
||||
docker exec -u 1000:1000 gitea \
|
||||
gitea dump --file /data/git/gitea-backup.zip
|
||||
#Comprueba que se ha generado:
|
||||
|
||||
docker exec gitea ls -lh /data/git/gitea-backup.zip
|
||||
#Copiar el backup al host:
|
||||
|
||||
docker cp gitea:/data/git/gitea-backup.zip ./gitea-backup.zip
|
||||
#Comprueba cuántos repositorios tiene realmente el dump
|
||||
unzip -l gitea-backup.zip | grep '\.git/'
|
||||
#Extraer el zip en una carpeta
|
||||
unzip gitea-backup.zip -d nombrecarpeta
|
||||
```
|
||||
|
||||
En un gitea dump, los repositorios normalmente están dentro del ZIP bajo una estructura parecida a:
|
||||
---
|
||||
|
||||
gitea-dump-2026-08-04.zip
|
||||
├── app.ini
|
||||
├── custom/
|
||||
├── data/
|
||||
├── log/
|
||||
├── repos/
|
||||
│ ├── usuario1/
|
||||
│ │ ├── repo1.git/
|
||||
│ │ └── repo2.git/
|
||||
│ └── usuario2/
|
||||
│ └── proyecto.git/
|
||||
└── ...
|
||||
## 11. Gitea con snap
|
||||
|
||||
Gitea (arrancar y parar) Instalado desde snap
|
||||
|
||||
Si el repositorio estaba, por ejemplo, en:
|
||||
repos/pepe/web.git/
|
||||
haz:
|
||||
```git clone repos/pepe/web.git web```
|
||||
localhost:3000 (puerto 3000)
|
||||
|
||||
```bash
|
||||
script sh
|
||||
#!/bin/bash
|
||||
BACKUP="gitea-backup-$(date +%Y-%m-%d).zip"
|
||||
docker exec -u 1000:1000 gitea \
|
||||
gitea dump --file "/data/git/$BACKUP"
|
||||
docker cp "gitea:/data/git/$BACKUP" "./$BACKUP"
|
||||
```
|
||||
|
||||
**Restore**
|
||||
|
||||
1️⃣ Copia el dump al contenedor (si no está ya dentro)
|
||||
Si el ZIP está en el host:
|
||||
```docker cp gitea-dump-YYYY-MM-DD.zip gitea:/data/```
|
||||
|
||||
2️⃣ Detén el contenedor de Gitea
|
||||
```docker stop gitea```
|
||||
|
||||
⚠️ Importante: no restaures con Gitea corriendo.
|
||||
3️⃣ Entra al contenedor
|
||||
```docker exec -it gitea bash```
|
||||
|
||||
4️⃣ Ejecuta la restauración
|
||||
```gitea restore --file /data/gitea-dump-YYYY-MM-DD.zip```
|
||||
|
||||
Esto:
|
||||
- Restaura repositorios
|
||||
- Restaura base de datos
|
||||
- Restaura configuración
|
||||
- Restaura issues, PRs, usuarios, etc.
|
||||
|
||||
5️⃣ Sal y arranca el contenedor
|
||||
```
|
||||
exit
|
||||
docker start gitea
|
||||
```
|
||||
|
||||
**Gitea en volumen docker.**
|
||||
Copiar directamente los volúmenes (rápida y eficaz)
|
||||
Si usas `docker-compose`, normalmente tienes algo así:
|
||||
`volumes: - ./gitea:/data`
|
||||
`docker compose down`
|
||||
tar czvf gitea_backup.tar.gz gitea/`
|
||||
`docker compose up -d`
|
||||
|
||||
|
||||
###### Copiar solo los repositorios (NO recomendado como único backup)
|
||||
|
||||
Los repositorios están en:
|
||||
`/data/git/repositories`
|
||||
Puedes copiarlos así:
|
||||
`docker cp gitea:/data/git/repositories ./repos_backup`
|
||||
|
||||
---
|
||||
|
||||
|
||||
**Gitea snap**
|
||||
**backup**
|
||||
`sudo gitea dump`
|
||||
Esto genera un archivo como:
|
||||
`gitea-dump-YYYY-MM-DD.zip`
|
||||
Por defecto se guarda en: /var/snap/gitea/common
|
||||
|
||||
**Restaurar**
|
||||
1️⃣ Detén Gitea:
|
||||
`sudo snap stop gitea`
|
||||
2️⃣ Restaura:
|
||||
`sudo gitea restore --file gitea-dump-YYYY-MM-DD.zip`
|
||||
3️⃣ Arranca Gitea:
|
||||
`sudo snap start gitea`
|
||||
|
||||
|
||||
**Backup automático con cron (recomendado) Snap**
|
||||
Ejemplo de **backup diario a las 2:00 AM**:
|
||||
`sudo crontab -e`
|
||||
|
||||
Añade:
|
||||
`0 2 * * * gitea dump --file /var/backups/gitea/gitea-$(date +\%F).zip`
|
||||
(asegúrate de crear antes la carpeta `/var/backups/gitea`)
|
||||
|
||||
|
||||
|
||||
|
||||
| Comando | Acción |
|
||||
|---|---|
|
||||
| `sudo snap start gitea` | Iniciar Gitea |
|
||||
| `sudo snap stop gitea` | Detener Gitea |
|
||||
| `sudo snap services gitea` | Verificar estado |
|
||||
| `sudo snap disable gitea` | Deshabilitar inicio |
|
||||
| `sudo snap restart gitea` | Reiniciar Gitea |
|
||||
| `sudo snap remove gitea` | Eliminar Gitea |
|
||||
|
||||
---
|
||||
|
||||
## 12. Resumen
|
||||
|
||||
Los comandos clave del día a día son:
|
||||
|
||||
- `git status`
|
||||
- `git add .`
|
||||
- `git commit -m "..."`
|
||||
- `git branch`
|
||||
- `git switch`
|
||||
- `git pull`
|
||||
- `git push`
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user