Beginner

Git Workflows Cheatsheet

Quick reference for Git — everyday commands, branching and merging, remotes, merge vs rebase, conflict resolution, undoing changes, stash, and tags.

BranchingMergeRebaseRemotes
NotesCheatsheet

Everyday Commands

Setup & Snapshot

git init                    # new repo
git clone URL               # copy a remote repo
git status                  # what changed / staged
git add .                   # stage everything
git add file.js             # stage one file
git commit -m "message"     # commit staged
git commit -am "message"    # stage tracked + commit
git log --oneline --graph --all
git diff                    # working tree vs staged
git diff --staged           # staged vs last commit

Three Areas

working tree  --git add-->  staging  --git commit-->  repo
   (edits)                   (index)                  (history)

Branching & Merging

git switch -c feature/x     # create + switch (2.23+)
git checkout -b feature/x   # older equivalent
git branch                  # list
git switch main             # switch
git merge feature/x         # merge into current branch
git branch -d feature/x     # delete merged branch
git branch -D feature/x     # force delete

Remotes

git remote -v               # list remotes
git fetch origin            # download, no merge
git pull                    # fetch + merge
git push -u origin feature/x# first push, set upstream
git push                    # subsequent pushes
git push origin --tags      # push all tags
CmdDirectionMerges?
fetchremote → localNo
pullremote → localYes
pushlocal → remote—

Merge vs Rebase

git merge main       # keep both histories + merge commit
git rebase main      # replay commits on top of main (linear)
git rebase --continue / --abort / --skip
MergeRebase
HistoryNon-linearLinear
HashesKeptRewritten
Shared?SafeNever on pushed

Golden rule

Never rebase commits others have already pulled.

Conflicts

<<<<<<< HEAD
your change
=======
their change
>>>>>>> other-branch

# edit to final version, remove markers, then:
git add file.js
git commit                  # or: git rebase --continue
git merge --abort           # bail out entirely

Undo & Stash

git restore file.js         # discard unstaged edits
git restore --staged file   # unstage (keep edits)
git reset --soft HEAD~1     # undo commit, keep staged
git reset HEAD~1            # undo commit, keep in tree
git reset --hard HEAD~1     # discard commit + changes (!)
git revert <commit>         # inverse commit (safe on shared)
git stash / stash pop / stash list
ToolUse when
restoreDrop uncommitted edits
resetUndo local unpushed commits
revertUndo shared commits
stashShelve work-in-progress

Tags & .gitignore

git tag v1.0.0                       # lightweight
git tag -a v1.0.0 -m "Release 1.0"   # annotated
git push origin v1.0.0               # push one tag

# .gitignore
node_modules/
dist/
.env
.DS_Store
git rm --cached file   # stop tracking an already-committed file

Workflows

WorkflowShape
Feature BranchBranch per task → PR → merge to main
GitHub Flowmain always deployable; branch, PR, merge, deploy
Git Flowmain + develop + feature/release/hotfix branches
# PR loop
git switch -c feature/x
# commit work...
git push -u origin feature/x
# open PR, review, address feedback, merge (squash common)

Section navigation