Git Workflow
Having used Git for many years, I often find myself needing to revisit certain operations, especially when it comes to tasks like discarding changes across different areas (workspace, index/staging, local repo and remote repo). To streamline my workflow and make these operations easier to recall, I've compiled a collection of common Git commands and workflows. I've found that visualizing these workflows through diagrams is incredibly helpful for quick picking up the needed information.
Basic git operations
Mermaid Source
graph TD A[Workspace] -->|git add| B[Index/Stage] B -->|git commit| C[Local Repository] C -->|git push| D[Remote Repository] D -->|git pull| C C -->|git checkout| A C -->|git merge| A C -->|git fetch| DWorking on branch
Mermaid Source
graph TD A[Remote Repository - Init Commit] A -->|git clone| B[Local Repository] B -->|git checkout -b feature-branch| C[Local Repository - Feature Branch] C -->|make changes| D[Local Workspace] D -->|git add| E[Staging Area] E -->|git commit| F[Local Repository - Feature Branch - New Commit] F -->|git push origin feature-branch| G[Remote Repository - Feature Branch]
Sync with remote then commit
Undo changes
Undo working directory changes
Undo changes in staging area
Undo changes in both working directory and staging area
More on resets
Revert
