Network
Language · FA
Dark mode

REFERENCE

Git Workflows

4 workflow strategies + 40+ commands with descriptions.

Workflow Strategies

Git Flow

Two long-lived branches: main (production) + develop (integration). Short-lived: feature/*, release/*, hotfix/*. Best for: versioned products, scheduled releases.

main ─────────────────── v1.0
develop ──┬──┬──────────
feature ──┘ │
release ─────┘

GitHub Flow

One long-lived branch: main. Feature branches created, then merged via PR directly to main. Requires CI. Best for: SaaS, continuous deployment.

main ──────────────────
feat ──branch──PR──merge

Trunk-Based

All developers commit to main daily. Feature flags control incomplete features in production. No long-lived branches. Best for: large teams, high velocity.

main ← all commits daily
feature flags in code

Forking Workflow

Each contributor forks the upstream repo. PRs go from fork → upstream main. Best for: open-source projects where maintainers don't know all contributors.

Git Command Reference

CategoryCommandDescription
Init & Clonegit initInitialize new local repository
Init & Clonegit clone <url>Clone remote repository
Init & Clonegit clone --depth 1 <url>Shallow clone (latest commit only)
Stage & Commitgit statusShow working tree status
Stage & Commitgit add <file>Stage specific file
Stage & Commitgit add -pStage hunks interactively
Stage & Commitgit commit -m 'msg'Commit staged changes
Stage & Commitgit commit --amendAmend last commit (do not amend pushed commits)
Branchinggit branch <name>Create branch
Branchinggit switch <name>Switch to branch
Branchinggit switch -c <name>Create + switch
Branchinggit branch -d <name>Delete merged branch
Branchinggit branch -D <name>Force-delete branch
Merge & Rebasegit merge <branch>Merge branch into current (preserves history)
Merge & Rebasegit merge --squash <branch>Squash all commits into one
Merge & Rebasegit rebase <base>Rebase current branch onto base
Merge & Rebasegit rebase -i HEAD~3Interactive rebase: squash/edit/drop last 3
Remotegit remote add origin <url>Add remote
Remotegit fetchDownload remote changes (no merge)
Remotegit pullFetch + merge current branch
Remotegit pull --rebaseFetch + rebase (cleaner history)
Remotegit push -u origin <branch>Push and set upstream
Remotegit push --force-with-leaseSafe force push (checks remote)
Inspectgit log --oneline --graphCompact visual branch graph
Inspectgit log -p <file>Show changes to specific file
Inspectgit diffShow unstaged changes
Inspectgit diff --stagedShow staged changes
Inspectgit blame <file>Show who changed each line
Inspectgit show <commit>Show commit details + diff
Undogit restore <file>Discard unstaged changes to file
Undogit restore --staged <file>Unstage file
Undogit reset HEAD~1Undo last commit (keep changes staged)
Undogit reset --hard HEAD~1Undo last commit (discard changes — dangerous)
Undogit revert <commit>Create new commit that undoes a commit (safe)
Stashgit stashStash uncommitted changes
Stashgit stash popRestore last stash
Stashgit stash listList all stashes
Tagsgit tag v1.0.0Create lightweight tag
Tagsgit tag -a v1.0.0 -m 'msg'Annotated tag with message
Tagsgit push origin --tagsPush all tags
Submodulesgit submodule add <url>Add submodule
Submodulesgit submodule update --init --recursiveInit + update all submodules

Commit Message Convention

TypeWhen to UseExample
featNew featurefeat: add OAuth2 login
fixBug fixfix: handle null user in auth middleware
docsDocumentation onlydocs: update API reference
styleFormatting, no logic changestyle: normalize indentation
refactorNeither fix nor featurerefactor: extract user service
testAdding teststest: add unit tests for cart module
choreBuild/tooling changeschore: upgrade dependencies
perfPerformance improvementperf: cache DB query results
ciCI/CD changesci: add GitHub Actions workflow