Table of Contents
- 11 - Troubleshooting
- Problemi Autenticazione HTTPS
- Problemi Push/Pull
- Errore: non-fast-forward
- Errore: no upstream branch
- Errore: merge conflict
- Errore: would be overwritten
- Problemi Repository
- Problemi Connessione
- Problemi File
- Problemi Configurazione
- Problemi Performance
- Recovery - Operazioni di Salvataggio
- Ho cancellato commit per errore
- Ho fatto reset --hard per errore
- Ho cancellato branch
- File non committato cancellato
- Best Practices per Evitare Problemi
- 1. Pull Prima di Push
- 2. Status Prima di Operazioni
- 3. Commit Frequenti
- 4. Branch per Feature
- 5. Backup con Stash
- Tool Utili Debug
- 🔗 Collegamenti
- 📝 Quick Fixes
11 - Troubleshooting
Errori comuni con Git e HTTPS, soluzioni e best practices.
Problemi Autenticazione HTTPS
Errore: Authentication failed
fatal: Authentication failed for 'https://git.emanuelegori.uno/user/repo.git/'
Cause:
- Token sbagliato o scaduto
- Username errato
- Credential helper con credenziali vecchie
Soluzioni:
# 1. Verifica username
git config user.name
# 2. Rigenera token su Forgejo
# Settings → Applications → Generate New Token
# 3. Pulisci credenziali salvate
git credential reject <<EOF
protocol=https
host=git.emanuelegori.uno
EOF
# 4. Riprova (inserirà nuovo token)
git pull origin main
Errore: No credential helper
warning: credential helper 'store' is not available
Soluzione:
# Configura credential helper
git config --global credential.helper store
# Alternative più sicure:
git config --global credential.helper cache
git config --global credential.helper 'cache --timeout=3600'
Errore: Token non funziona
Token inserito ma continua a chiedere password.
Causa: Fine-grained token senza permessi corretti
Soluzione:
# Su Forgejo, quando generi token:
# ✅ Seleziona: write:repository, read:repository
# ❌ Non selezionare solo: read:user
# Rigenera token con permessi corretti
# Pulisci cache e riprova
Problemi Push/Pull
Errore: non-fast-forward
! [rejected] main -> main (non-fast-forward)
error: failed to push some refs to 'https://git.emanuelegori.uno/user/repo.git'
Causa: Qualcuno ha pushato mentre lavoravi
Soluzione:
# Opzione 1: Pull + merge
git pull origin main
# Risolvi eventuali conflitti
git push origin main
# Opzione 2: Pull con rebase (cronologia più pulita)
git pull --rebase origin main
git push origin main
# Opzione 3: Force push (SOLO se sei SICURO!)
git push --force-with-lease origin main
Errore: no upstream branch
fatal: The current branch feature has no upstream branch.
Causa: Branch mai pushato, no upstream configurato
Soluzione:
# Push e configura upstream
git push -u origin feature
# D'ora in poi basta:
git push
git pull
Errore: merge conflict
CONFLICT (content): Merge conflict in src/app.py
Automatic merge failed; fix conflicts and then commit the result.
Soluzione:
# 1. Vedi file in conflitto
git status
# both modified: src/app.py
# 2. Apri file, trova markers
# <<<<<<< HEAD
# tuo codice
# =======
# codice remoto
# >>>>>>> branch
# 3. Risolvi manualmente (scegli o combina)
# 4. Rimuovi markers (<<<<, ====, >>>>)
# 5. Staging file risolto
git add src/app.py
# 6. Completa merge
git commit
# 7. Push
git push origin main
Errore: would be overwritten
error: Your local changes to the following files would be overwritten by merge:
config.ini
Please commit your changes or stash them before you merge.
Soluzione:
# Opzione 1: Commit modifiche
git add config.ini
git commit -m "Update config"
git pull
# Opzione 2: Stash temporaneo
git stash
git pull
git stash pop
# Opzione 3: Scarta modifiche (ATTENZIONE!)
git restore config.ini
git pull
Problemi Repository
Errore: repository not found
fatal: repository 'https://git.emanuelegori.uno/user/repo.git/' not found
Cause:
- URL sbagliato (typo)
- Repository privato senza autenticazione
- Repository non esiste
Soluzioni:
# 1. Verifica URL
git remote -v
# 2. Correggi se sbagliato
git remote set-url origin https://git.emanuelegori.uno/USER/REPO.git
# 3. Se privato, verifica token
git ls-remote https://git.emanuelegori.uno/user/repo.git
# 4. Verifica esistenza su Forgejo web UI
Errore: not a git repository
fatal: not a git repository (or any of the parent directories): .git
Causa: Non sei in directory Git
Soluzione:
# Opzione 1: Vai in directory corretta
cd /percorso/tuo-repo
# Opzione 2: Inizializza Git
git init
# Opzione 3: Clone repository
git clone https://git.emanuelegori.uno/user/repo.git
Problemi Connessione
Errore: SSL certificate problem
fatal: unable to access 'https://git.emanuelegori.uno/user/repo.git/':
SSL certificate problem: unable to get local issuer certificate
Causa: Certificato SSL non verificato
Soluzioni:
# ❌ NON FARE (insicuro):
git config --global http.sslVerify false
# ✅ Soluzioni corrette:
# 1. Aggiorna certificati sistema
sudo apt update
sudo apt install ca-certificates
# 2. Verifica certificato Forgejo
curl -v https://git.emanuelegori.uno 2>&1 | grep -i certificate
# 3. Se Let's Encrypt valido, aggiorna Git
git --version # Aggiorna se vecchio
Errore: could not resolve host
fatal: unable to access 'https://git.emanuelegori.uno/user/repo.git/':
Could not resolve host: git.emanuelegori.uno
Cause:
- DNS non risolve
- Network down
- Typo dominio
Soluzioni:
# 1. Verifica connessione
ping git.emanuelegori.uno
# 2. Verifica DNS
nslookup git.emanuelegori.uno
# 3. Test curl
curl -I https://git.emanuelegori.uno
# 4. Verifica /etc/hosts (se custom DNS)
cat /etc/hosts | grep emanuelegori
Problemi File
Errore: filename too long
error: unable to create file very/long/path/to/file.txt: Filename too long
Causa: Windows ha limite 260 caratteri path
Soluzione:
# Abilita long paths (Windows)
git config --global core.longpaths true
Errore: CRLF will be replaced
warning: CRLF will be replaced by LF in file.txt
Causa: Differenze line ending Windows/Linux
Soluzioni:
# Opzione 1: Auto-convert (raccomandato)
git config --global core.autocrlf true # Windows
git config --global core.autocrlf input # Linux/Mac
# Opzione 2: Disable warning
git config --global core.safecrlf false
Errore: LFS required
Error: File too large (>100MB)
Causa: GitHub/GitLab limitano file a 100MB
Soluzione:
# Forgejo self-hosted di solito NON ha limite
# Ma per file grandi è meglio Git LFS
# 1. Installa Git LFS
sudo apt install git-lfs
# 2. Inizializza
git lfs install
# 3. Traccia file grandi
git lfs track "*.zip"
git lfs track "*.bin"
# 4. Commit .gitattributes
git add .gitattributes
git commit -m "Add LFS tracking"
Problemi Configurazione
Errore: Please tell me who you are
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
Soluzione:
git config --global user.name "Emanuele Gori"
git config --global user.email "email@esempio.com"
# Verifica
git config --list | grep user
Errore: refusing to merge unrelated histories
fatal: refusing to merge unrelated histories
Causa: Due repository senza storia comune
Soluzione:
# Forza merge (se sicuro)
git pull origin main --allow-unrelated-histories
# Risolvi conflitti se presenti
Problemi Performance
Git lentissimo
Cause:
- Repository molto grande
- Troppi file
- Network lento
Soluzioni:
# 1. Clone shallow (solo ultimi commit)
git clone --depth 1 https://git.emanuelegori.uno/user/repo.git
# 2. Clone single branch
git clone --single-branch --branch main https://git.emanuelegori.uno/user/repo.git
# 3. Garbage collection
git gc --aggressive --prune=now
# 4. Compressione migliore
git config --global pack.compression 9
Recovery - Operazioni di Salvataggio
Ho cancellato commit per errore
# 1. Trova commit nel reflog
git reflog
# 2. Identifica commit perso
# abc123 HEAD@{5}: commit: Important work
# 3. Recupera
git reset --hard abc123
# oppure
git checkout -b recovery abc123
Ho fatto reset --hard per errore
# Stesso procedimento reflog
git reflog
git reset --hard HEAD@{1}
Ho cancellato branch
# 1. Trova ultimo commit del branch nel reflog
git reflog | grep "branch-name"
# 2. Ricrea branch
git branch branch-name abc123
File non committato cancellato
Purtroppo: Se mai aggiunto a Git, irrecuperabile.
Prevenzione:
# Backup automatico con stash
git stash -u -m "Backup before risky operation"
# Se va male
git stash pop
Best Practices per Evitare Problemi
1. Pull Prima di Push
# ✅ Workflow corretto
git pull origin main
git push origin main
# ❌ Evita
git push # Senza pull prima
2. Status Prima di Operazioni
# Sempre verifica stato
git status
# Prima di:
git pull
git checkout
git reset
git merge
3. Commit Frequenti
# ✅ Commit spesso (WIP ok)
git commit -m "WIP: feature in progress"
# ❌ Evita di accumulare giorni di lavoro
4. Branch per Feature
# ✅ Branch separati
git switch -c feature-login
# ❌ Tutto su main
5. Backup con Stash
# Prima di operazioni rischiose
git stash -u -m "Backup"
# Operazione...
# Se ok
git stash drop
# Se male
git stash pop
Tool Utili Debug
Git Verbose
# Debug push/pull
GIT_TRACE=1 GIT_CURL_VERBOSE=1 git push origin main
# Debug autenticazione
GIT_TRACE=1 GIT_CURL_VERBOSE=1 git clone https://...
Verifica Config
# Tutte le config
git config --list --show-origin
# Config specifiche
git config --get remote.origin.url
git config --get user.name
Health Check Repository
# Verifica integrità
git fsck --full
# Statistiche
git count-objects -vH
🔗 Collegamenti
- Precedente: ← Tabella HTTPS vs SSH
- Indice: ← Torna all'indice
- README: ← Setup Iniziale
📝 Quick Fixes
# AUTENTICAZIONE
git credential reject <<EOF
protocol=https
host=git.emanuelegori.uno
EOF
# PULL RIFIUTATO
git pull --rebase origin main
# CONFLITTI
git status # Vedi file
# Risolvi manualmente
git add file.txt
git commit
# RECOVERY
git reflog
git reset --hard HEAD@{N}
# PULIZIA
git clean -fd
git gc --aggressive
Hai un problema non listato? Apri una issue sul repository! 🎯