# Workflow ideale per lavorare su un task ## 1. Assicurarsi di essere aggiornati Prima di iniziare a lavorare: ```bash git fetch origin git status ``` Se la tua branch locale è dietro rispetto a `origin/`: ```bash git merge origin/ # oppure, se sai cosa fai: # git pull ``` Esempio, se lavori su `develop`: ```bash git checkout develop git fetch origin git merge origin/develop ``` > Nota: `git pull` = `git fetch` + `git merge` (vedi file dedicato). --- ## 2. Creare (o spostarsi su) la branch di lavoro Nel modello standard, tipicamente: * branch lunga vita: `master`, `development` * branch di feature: `feature/` Esempio nuova feature: ```bash git checkout development git pull origin development # se preferisci pull qui git checkout -b feature/nuovo-report ``` Ora sei su `feature/nuovo-report` e puoi lavorare. --- ## 3. Modificare i file e controllare lo stato Dopo aver modificato il codice: ```bash git status ``` Esempio: ```text On branch feature/nuovo-report Changes not staged for commit: modified: src/report.py Untracked files: docs/spec-report.md ``` --- ## 4. Aggiungere i file allo staging (`git add`) Aggiungi solo i file che devono entrare nel commit: ```bash git add src/report.py docs/spec-report.md ``` Per aggiungere tutte le modifiche tracciate e i nuovi file: ```bash git add . # oppure git add -A ``` Controlla: ```bash git status ``` Esempio: ```text Changes to be committed: modified: src/report.py new file: docs/spec-report.md ``` --- ## 5. Creare un commit (`git commit`) Usiamo messaggi brevi e descrittivi in inglese/italiano coerenti. ```bash git commit -m "Aggiunge report mensile con nuovo layout" ``` Oppure, per messaggi multi-riga: ```bash git commit # si apre l'editor configurato ``` Struttura consigliata: ```text Breve descrizione al presente - dettaglio 1 - dettaglio 2 ``` --- ## 6. Pubblicare la branch sul server (`git push`) Per la prima volta su una branch nuova: ```bash git push -u origin feature/nuovo-report ``` Il flag `-u` imposta il tracking Altrimenti è possibile utilizzare `--set-upstream` in futuro basterà lanciare: ```bash git push ``` Esempio di output: ```text Counting objects: 7, done. Delta compression using up to 8 threads. ... To https://www.meridianaitalia.eu/Meridiana/progetto/repo.git * [new branch] feature/nuovo-report -> feature/nuovo-report Branch 'feature/nuovo-report' set up to track remote branch 'feature/nuovo-report' from 'origin'. ``` --- ## 7. Creare la Merge Request / Pull Request Dal sistema di gestione (nel nostro caso **Gogs**): 1. Scegli come **source branch**: `feature/nuovo-report` 2. Scegli come **target branch**: di solito `develop` 3. Assegna revisori, descrivi cosa fa la feature 4. Una volta approvata si fa il **merge** in `develop` --- ## Riepilogo rapido workflow ```bash # una volta che hai clonato il repo git checkout develop git pull origin develop git checkout -b feature/nuovo-report # ...modifichi file... git status git add file1 file2 git commit -m "Messaggio chiaro" git push -u origin feature/nuovo-report # poi apri la MR/PR da interfaccia web ```