Git Workflow
A change moves through four places. Only the last one is shared with others; everything before push can still be
rewritten freely.
sequenceDiagram participant W as Working tree participant I as Index (staging) participant L as Local repository participant R as Remote W->>I: git add I->>L: git commit L->>R: git push R->>L: git fetch L->>W: git switch / git merge Note over W,R: git pull = fetch + merge (or rebase)
| Place | Contains | Inspect with |
|---|---|---|
| Working tree | The files you edit. | git status, git diff |
| Index | The snapshot the next commit will contain. | git diff --staged |
| Local repository | All commits; HEAD points to the checked-out one. |
git log --oneline --graph |
| Remote | The shared copy, mirrored locally as origin/<branch>. |
git log origin/main |
Feature branch workflow
Section titled “Feature branch workflow”git switch -c feature/login # new branch from the current onegit add -p # stage changes hunk by hunkgit commit -m "Add login form"git push -u origin feature/login # -u: later pushes need no argumentsThen open a pull request, or merge locally:
git switch maingit pullgit merge feature/logingit pushgit branch -d feature/login