A practical, terminal-first Git reference you can use as a quick professional guide.
Git has four main states:
- Working directory: your current files
- Staging area: what goes into the next commit
- Local repository: your local commit history
- Remote repository: shared history on GitHub/GitLab/etc.
The professional habit is simple:
check → review → stage → commit → sync → push
flowchart TD
%% Styles
classDef setup fill:#e1f5fe,stroke:#01579b,stroke-width:2px;
classDef dev fill:#e8f5e9,stroke:#1b5e20,stroke-width:2px;
classDef sync fill:#fff9c4,stroke:#f57f17,stroke-width:2px;
classDef cleanup fill:#ffebee,stroke:#b71c1c,stroke-width:2px;
classDef decision fill:#ffcc80,stroke:#e65100,stroke-width:2px;
classDef startend fill:#f3e5f5,stroke:#4a148c,stroke-width:4px,color:#4a148c;
%% Setup Phase
subgraph Setup_Phase ["🚀 Setup Phase"]
A((Spin Up Environment)):::startend
B[Create or Clone Repository]:::setup
end
%% Development Phase
subgraph Dev_Phase ["💻 Development Phase"]
C[Create Feature Branch]:::dev
D[Edit Files]:::dev
E{Review Changes?}:::decision
F[Stage Changes]:::dev
G[Commit with Message]:::dev
end
%% Sync & Integration Phase
subgraph Sync_Phase ["🔄 Sync & Integration"]
H[Fetch / Pull Latest]:::sync
I{Rebase or Merge<br/>Conflicts?}:::decision
J[Resolve Conflicts]:::sync
K[Push Branch]:::sync
L[Open Pull Request]:::sync
M{PR Review}:::decision
N[Merge PR]:::sync
end
%% Cleanup Phase
subgraph Cleanup_Phase ["🧹 Cleanup"]
O[Pull Updated Main]:::cleanup
P[Delete Old Branches]:::cleanup
Q((Archive / Spin Down)):::startend
end
%% Connections
A --> B
B --> C
C --> D
D --> E
E -- "Ready" --> F
E -- "Needs Work" --> D
F --> G
G --> H
H --> I
I -- "No Conflicts" --> K
I -- "Conflicts" --> J
J --> F
K --> L
L --> M
M -- "Approved" --> N
M -- "Changes Requested" --> D
N --> O
O --> P
P --> Q
%% Legend (optional)
Legend[<b>Legend</b><br/>🟦 Setup 🟩 Development<br/>🟨 Sync 🟥 Cleanup<br/>🟧 Decision 🟪 Start/End]:::legend
classDef legend fill:#f5f5f5,stroke:#666,stroke-dasharray: 5 5,color:#333;
mkdir my-project
cd my-project
git init
git branch -M maingit add .
git commit -m "Initial commit"git remote add origin git@github.com:username/repo-name.git
git push -u origin maingit clone git@github.com:username/repo-name.git
cd repo-nameThis section is the closest thing to a clean terminal-only workflow for spinning up and maintaining a repo professionally.
git --version
gh --versiongit config --global user.name "Your Name"
git config --global user.email "you@example.com"git config --global init.defaultBranch main
git config --global pull.rebase true
git config --global fetch.prune true
git config --global rebase.autoStash true
git config --global push.default simplegit config --global --listgh auth login
gh auth statusGo into your project directory:
cd /path/to/your/projectInitialize Git:
git init
git branch -M mainCreate a .gitignore:
nano .gitignoreExample .gitignore starter:
__pycache__/
*.pyc
.venv/
.env
.DS_Store
.vscode/
.idea/
dist/
build/
*.logCheck what files exist:
git status -uStage and commit:
git add .
git commit -m "v0.1 initial project scaffold"Create the GitHub repo from the terminal and push in one step:
gh repo create repo-name --private --source=. --remote=origin --pushCheck the remote:
git remote -vThat is the cleanest terminal-only path.
Initialize locally:
git init
git branch -M mainAdd files:
git add .
git commit -m "Initial commit"Add the remote manually:
git remote add origin git@github.com:username/repo-name.gitVerify:
git remote -vPush:
git push -u origin mainThis is the professional terminal habit loop:
git status -sb
git diff
git add -p
git commit -m "feat: describe change"
git fetch origin
git rebase origin/main
git pushIf working directly on main in a solo repo, the loop is usually:
git status -sb
git add .
git commit -m "Describe update"
git pull --rebase
git pushCreate and switch:
git switch -c feature/my-changeWork normally:
git status -sb
git add -p
git commit -m "feat: add my change"Sync with latest main:
git fetch origin
git rebase origin/mainPush branch:
git push -u origin feature/my-changeAfter merge, clean up:
git switch main
git pull --rebase
git branch -d feature/my-change
git push origin --delete feature/my-changeIf the repo is done and you want to clean it up:
git switch main
git pull --rebase
git branch --merged
git branch -d branch-namegit fetch --prunegit remote remove originrm -rf .gitcd ..
rm -rf repo-nameflowchart TD
A[Open Terminal in Project Folder] --> B[git init]
B --> C[Create .gitignore]
C --> D[git add .]
D --> E[git commit -m Initial commit]
E --> F[gh auth login]
F --> G[gh repo create repo-name --source=. --remote=origin --push]
G --> H[Daily Work]
H --> I[git status]
I --> J[git add / git add -p]
J --> K[git commit]
K --> L[git fetch origin]
L --> M[git rebase origin/main]
M --> N[git push]
N --> O[Repo Complete]
O --> P[Cleanup branches]
P --> Q[Archive / remove remote / delete local copy]
git status
git status -sb
git remote -v
git branch
git branch -vvgit diff
git diff --staged
git showgit add .
git add FILE
git add -p
git restore --staged FILEgit commit -m "Short message"
git commit
git commit --amendgit pull --rebase
git push
git push -u origin maingit fetch origin
git fetch --all --prunegit switch -c feature/new-workgit switch main
git switch feature/new-workgit branch
git branch -a
git branch -vvgit branch -M maingit branch -d feature/new-work
git branch -D feature/new-workgit log --oneline --decorate --graph --allgit log -n 10git show <commit>git blame path/to/filegit restore FILE
git restore .git restore --staged FILE
git restore --staged .git revert <commit>git reset --soft HEAD~1
git reset --mixed HEAD~1
git reset --hard HEAD~1git refloggit fetch origin
git rebase origin/maingit merge feature/my-changegit rebase -i HEAD~5git status
# fix files
git add .
git rebase --continueAbort if needed:
git rebase --abortUseful when you need to pause work quickly.
git stash
git stash push -m "wip"
git stash push -u -m "wip including untracked"
git stash list
git stash pop
git stash apply stash@{0}git remote -vgit remote add origin git@github.com:username/repo-name.gitgit remote set-url origin git@github.com:username/repo-name.gitgit remote remove origingit tag v1.0.0
git tag -a v1.0.0 -m "Release v1.0.0"git push origin v1.0.0
git push origin --tagsgit tag -d v1.0.0
git push origin --delete v1.0.0git fetch --prunegit branch --mergedgit clean -nfd
git clean -fdgit gccd /path/to/project
git init
git branch -M main
nano .gitignore
git add .
git commit -m "Initial commit"
gh auth login
gh repo create repo-name --private --source=. --remote=origin --push
git remote -v
git status -ucd /path/to/project
git init
git branch -M main
git add .
git commit -m "Initial commit"
git remote add origin git@github.com:username/repo-name.git
git remote -v
git push -u origin maingit status -sb
git add -p
git commit -m "fix: update logic"
git pull --rebase
git pushgit switch main
git pull --rebase
git switch -c feature/my-work
# make changes
git add .
git commit -m "feat: add new work"
git fetch origin
git rebase origin/main
git push -u origin feature/my-workgit switch main
git pull --rebase
git branch -d feature/my-work
git push origin --delete feature/my-work
git fetch --pruneYou had the right idea, but a few commands needed cleanup.
git init
nano .gitignore
git add .
git commit -m "v0.1 of project"
git config --global --list
gh --version
gh auth login
gh repo create repo-name --private --source=. --remote=origin --push
git remote -v
git branch -M main
git push -u origin main
git status -uThis is wrong:
git branch push -u origin mainUse:
git push -u origin mainThis may be redundant if gh repo create ... --remote=origin --push already succeeded:
git remote add origin git@github.com:username/repo-name.gitThat command is only needed when you are adding the remote manually.
Use these consistently:
- Run
git status -sbconstantly - Use
git add -pinstead of blindly staging everything when changes are mixed - Prefer
git pull --rebaseover noisy merge commits for your own feature branches - Use clear commit messages
- Verify remotes with
git remote -v - Clean merged branches regularly
- Use
gh repo createwhen starting a GitHub-backed repo from terminal - Learn
reflogbefore you need it
A simple professional pattern:
feat: add resume tailoring pipeline
fix: correct branch push instructions
docs: expand git cheat sheet
refactor: simplify repo bootstrap flow
chore: update gitignoreIf you remember nothing else, remember this:
git status -sb
git add -p
git commit -m "feat: meaningful message"
git fetch origin
git rebase origin/main
git pushThat sequence alone will cover a huge percentage of professional Git usage cleanly.
If you want, I can turn this into a polished README.md file with cleaner section anchors and copy-paste formatting for GitHub.