Git Cheatsheet
Guida di riferimento rapido per comandi Git essenziali. Cheatsheet ricercabile che copre branch, commit, merge e altro.
Flusso di lavoro del team
Negli ambienti professionali, i team seguono tipicamente una strategia di branching dove ogni attività ha il proprio branch. Questo isola le funzionalità e impedisce al codice non finito di rompere l'applicazione principale.
Suggerimenti professionali: Punta sempre a commit piccoli e atomici. Prima di fondere il tuo lavoro, usa 'git fetch' e poi 'git rebase origin/dev' (o main) per assicurarti che il tuo codice sia compatibile con l'ultima versione. Infine, usa 'git push -f' sul tuo feature branch per aggiornare il remoto con la tua cronologia rebasata.
Configurazione
Imposta la configurazione globale
Configura la tua identità su tutti i repository del tuo sistema.
Inizia
Crea un repository git
Inizializza un nuovo repository Git nella directory corrente.
Clona un repository git esistente
Copia un repository Git esistente da un server remoto.
Commit
Conferma tutte le modifiche tracciate
Prepara e conferma tutti i file tracciati modificati in un unico comando.
Aggiungi nuove modifiche all'ultimo commit
Aggiorna l'ultimo commit con le modifiche correnti e opzionalmente cambia il messaggio.
Branching
Crea un nuovo branch
Crea un nuovo branch al puntatore corrente.
Passa a un branch
Sposta HEAD al branch specificato.
Fondi un branch nel branch corrente
Combina la cronologia di un altro branch nel tuo corrente.
Crea e passa a un branch
Il modo più comune per iniziare a lavorare su una nuova funzionalità.
Sincronizzazione
Recupera aggiornamenti dal remoto
Scarica le modifiche remote senza fonderle.
Scarica le ultime modifiche
Recupera le modifiche e tenta immediatamente di fonderle.
Rebasa il branch corrente su main
Riproduce i tuoi commit sull'ultimo branch main.
Invia modifiche (Forzato)
Forza l'aggiornamento del branch remoto con la tua cronologia locale. Usa solo su branch privati!
Comandi utili
Controlla lo stato
Vedi quali file sono modificati, preparati o non tracciati.
Nascondi modifiche
Nasconde temporaneamente le modifiche per lavorare su qualcos'altro.
Visualizza cronologia
Visualizza la cronologia dei commit su tutti i branch.
Come Usare Questo Git Cheatsheet
- Browse the cheatsheet to find the Git command you need.
- Commands are organized by category: Configuration, Get Started, Commit, Branching, Syncing, and Useful Commands.
- Click the copy button next to any command to copy it to your clipboard.
- Paste the command into your terminal and modify the placeholder values as needed.
Advanced Rebasing
Rebasing is often preferred over merging to maintain a clean, linear project history. Instead of creating a 'merge commit', it repositions your commits at the end of the target branch.
Tip
Remember: Never rebase a public branch that others are working on, as it rewrites history and can cause significant conflicts for your peers.
Key Features
- Essential Git commands organized by workflow category
- One-click copy for every command
- Clear descriptions explaining what each command does
- Covers configuration, branching, syncing, and more
- Team workflow guidance with professional tips
- Rebasing best practices and safety warnings
- Works offline once loaded in your browser
Common Use Cases
- Quick reference while working in the terminal
- Onboarding new developers to Git workflows
- Reviewing branching and merging strategies
- Learning Git commands for the first time
- Refreshing memory on less frequently used commands
- Setting up Git configuration on a new machine
Domande Frequenti
What is the difference between git merge and git rebase?
Git merge creates a new merge commit that combines two branches, preserving the full history. Git rebase replays your commits on top of the target branch, creating a linear history. Rebase produces a cleaner log but should never be used on shared public branches.
When should I use git stash?
Use git stash when you need to switch branches but have uncommitted changes you are not ready to commit. Stash saves your working directory state temporarily. You can restore it later with 'git stash pop' on any branch.
Is it safe to use git push --force?
Force pushing is safe only on branches that you alone work on, such as personal feature branches. Never force push to shared branches like main or develop, as it rewrites remote history and can cause other team members to lose their work.