The standard Git workflow follows a three-step cycle: Stage → Commit → Push . This is known as the Git Working Cycle or Git Staging Workflow , and it forms the core of the Feature Branch Workflow or Trunk-Based Development .
Step
Command
Background Operation
Stage
git add <file> or git add .
Git calculates SHA-1 hashes, creates blob objects in .git/objects/, and updates the index (.git/index) to represent the “next commit” state.
Commit
git commit -m "message"
Git creates a commit object with a tree object (directory structure), metadata (author, message, timestamps), and parent commit hash(es). It updates the branch reference and HEAD pointer.
Push
git push origin <branch>
Git connects to the remote, negotiates missing objects, packs local objects into a packfile, sends them, and updates the remote branch reference (fast-forward or forced update).
# 1. Stage changed files for commit
git add <file> # stage a specific file
git add . # stage all changed and new files in current directory
git add -u # stage all modified and deleted files (not new untracked)
git add -p # stage changes interactively, hunk by hunk
# 2. Commit changed files
git commit -m " message " # commit staged changes with a message
git commit -am " message " # stage all tracked changes + commit (no new files)
git commit --amend # edit last commit (message or contents)
# 3. Push changes to remote
git push # push current branch to its upstream remote
git push -u origin <branch> # push + set upstream tracking branch
git push --force-with-lease # safe force push (only if remote didn't change)
git push --force # force push (dangerous, overwrites remote)
Command
Action
git init
new repo
git clone <url>
clone a repo
git clone --depth 1 <url>
shallow clone (fast)
git config --global user.name "Name"
set global author name
git config --global user.email "email"
set global author email
git config --global core.editor "code"
set default editor
git branch # list local branches
git branch -a # list all (local + remote)
git branch -r # remote branches only
git switch <branch> # checkout a branch (modern)
git switch -c <branch> # create + switch
git switch -c <branch> <commit> # create from commit
git branch -d <branch> # delete merged branch
git branch -D <branch> # force delete unmerged
git branch -m <old> <new> # rename branch
git branch -vv # verbose: track + last commit
git worktree add ../other-branch feature/x # parallel checkout
git worktree list # list worktrees
git worktree remove ../other-branch # remove linked worktree
git worktree lock <path> # prevent removal while working
git status # working tree state
git status -sb # short + branch info
git diff # unstaged changes
git diff --staged # staged changes
git diff HEAD # all local changes
git diff <branch>..HEAD # changes vs branch
git diff --stat # stat-only diff
git diff --name-status # changed files + status
git log --oneline # compact single line
git log --oneline --graph --all # full branch graph
git log --oneline -10 # last 10 commits
git log --since= " 2 weeks ago " # time-filtered
git log --author= " Name " # by author
git log --grep= " keyword " # by commit message
git log -p -2 # last 2 commits with patches
git log --stat # with file-level stats
git log --follow <file> # track file across renames
git log --ancestry-path A..B # commits on path from A to B
git reflog # reference log (recover lost commits)
git describe --tags HEAD # human-readable ref name
git stash # save uncommitted changes
git stash list # list stashes
git stash pop # apply + remove top stash
git stash apply stash@{ 0 } # apply without removing
git stash drop stash@{ 0 } # delete a stash
git stash show -p stash@{ 0 } # view stash contents
git stash push -m " message " # stash with message
git stash push -u # include untracked files
git add <file> # stage a file
git add . # stage all changes
git add -p # stage hunks interactively
git commit -m " message " # commit with message
git commit -am " message " # stage all + commit (no new files)
git commit --amend # edit last commit
git commit --amend --no-edit # amend without changing message
git commit --dry-run # dry-run commit
git revert <commit> # create revert commit
git reset HEAD <file> # unstage a file
git reset --hard HEAD # discard ALL local changes
git reset --soft HEAD~1 # uncommit, keep changes staged
git reset --mixed HEAD~1 # uncommit, keep changes unstaged
git fetch # download remote refs
git fetch --all # fetch all remotes
git fetch --prune # fetch + remove stale remote refs
git pull --rebase # fetch + rebase (cleaner history)
git pull --rebase --autostash # rebase with auto-stash
git push # push current branch
git push -u origin <branch> # push + set upstream
git push --force-with-lease # safe force push
git push --force # force push (dangerous)
git push origin --delete <branch> # delete remote branch after merge
git remote -v # list remotes
git remote add origin <url> # add remote
git remote set-url origin <url> # change remote URL
git merge <branch> # merge branch into current
git merge --no-ff <branch> # always create merge commit
git merge --squash <branch> # squash merge (no commit)
git rebase <branch> # rebase current onto branch
git rebase -i HEAD~5 # interactive rebase (last 5)
git rebase --continue # continue after conflict resolve
git rebase --abort # abort rebase
git rebase --autostash # auto-stash before rebase
git cherry-pick <commit> # apply specific commit
git cherry-pick -n <commit> # cherry-pick without commit
# 1. Ensure you are on the target branch (e.g., main or develop)
# 2. Merge the feature branch
# 3. Delete local merged branch (safe: fails if not fully merged)
git branch -d feature-branch
# 4. Force delete local branch (ignores merge status)
git branch -D feature-branch
# 5. Delete the remote branch after merge
git push origin --delete feature-branch
git grep " pattern " # search file contents in repo
git grep -n " pattern " # with line numbers
git grep -p " pattern " # with matching patch
git blame <file> # line-by-line blame
git blame -L 10,20 <file> # blame lines 10-20
git show <commit> # show commit details
git show HEAD~2:file.txt # show file at specific commit
git tag -a v1.0 -m " release " # annotated tag
git tag -d <tag> # delete tag
git tag -l " v1.* " # list matching tags
git checkout v1.0 # checkout a tag (detached HEAD)
git switch --detach v1.0 # checkout tag (modern syntax)
git checkout -b feature v1.0 # create branch from tag
git switch -c feature v1.0 # create branch from tag (modern)
git push origin v1.0 # push a tag to remote
git push origin --tags # push all tags
Command
Action
git gc --auto
auto garbage collection
git gc --prune=now
aggressive cleanup
git fsck
verify object database
git clean -n
preview untracked files
git clean -fd
delete untracked files+dirs
git prune
remove unreachable objects
git maintenance start
start background maintenance (v2.41+)
git maintenance run
run maintenance tasks now
git clone --filter=blob:none <url> # partial clone (no blobs)
git sparse-checkout init # enable sparse checkout
git sparse-checkout set dir1 dir2 # checkout only dirs
git sparse-checkout list # list sparse patterns
Command
Action
git worktree add -b feature-x ../projects/feature-x HEAD
parallel checkout
git worktree list --verbose
list worktrees
git worktree move ../old-path ../new-path
relocate worktree
git worktree prune --expire 2.weeks.ago
clean stale worktrees