Back to it-tips
it-tips#git#version-control#cheat-sheet

Git Cheat Sheet: Every Command You'll Actually Use

From `git init` to `git rebase -i` — the practical Git workflow you'll use daily, with what each command really does.

TechNotesHub Team August 2, 2026 1 views
Log in to download the attached PDF

Git — the whole daily workflow

Mental model

+---------------+    add    +---------+   commit   +----------+   push   +---------+
| working dir   |  ------>  | staging |  ------>   |  local   |  ---->   | remote  |
| (your edits)  |           |  area   |            |  repo    |          | (GitHub)|
+---------------+           +---------+            +----------+          +---------+
       ^                                                                     |
       |------------------------  pull / clone  ----------------------------|

Set up

git config --global user.name  "Priya Sharma"
git config --global user.email "priya@example.com"
git config --global init.defaultBranch main

Start a repo

git init                              # new local repo
git clone https://github.com/x/y.git  # clone existing

Everyday flow

git status                            # what changed?
git add file.py                       # stage one file
git add .                             # stage everything
git commit -m "Add login form"        # commit staged
git log --oneline --graph --decorate  # nice history
git push                              # send to remote
git pull                              # bring remote changes

Branching

git branch                            # list local branches
git branch feature-login              # create branch
git checkout feature-login            # switch to it
git checkout -b feature-login         # create + switch (shortcut)

# In newer git:
git switch feature-login
git switch -c feature-login

Merge vs Rebase

        Merge                        Rebase
  A---B---C main                A---B---C---F'---G'  main
       \      \                          
        D---E---F feature       (D, E, F are re-applied on top of C)
                 \
                  G  merge commit
  • git merge feature-login — keeps history as it happened.
  • git rebase main (from feature-login) — replays your commits on top of main, cleaner history.

Rule: never rebase branches other people are also using.

Undoing

git restore file.py               # discard local edit (unstaged)
git restore --staged file.py      # unstage (keep edits)

git commit --amend                # edit the last commit
git reset --soft HEAD~1           # undo commit, keep staged
git reset --mixed HEAD~1          # undo commit + unstage (default)
git reset --hard HEAD~1           # undo commit + throw away edits (danger!)

git revert <commit>               # safe undo — makes a new commit

Stash — hide changes temporarily

git stash                         # tuck away current edits
git stash list                    # see stashes
git stash apply                   # bring them back (keep in stash)
git stash pop                     # bring back + remove from stash

Cherry-pick — grab one commit

git cherry-pick <sha>

Remote & push

git remote -v                     # show remotes
git remote add origin URL         # add remote called origin
git push -u origin main           # first push (sets upstream)

.gitignore in one minute

# comments start with #
node_modules/
*.log
.env
build/

Real-world flow (feature branch)

git checkout main && git pull
git checkout -b feature-search
# ... edit code ...
git add . && git commit -m "Add fuzzy search on notes"
git push -u origin feature-search
# open Pull Request on GitHub → review → merge
git checkout main && git pull
git branch -d feature-search

Beginner tips

  • Small commits > huge commits. Reviewers thank you.
  • Never commit secrets (.env files). Add to .gitignore before your first commit.
  • Use git log --oneline to make history readable.
  • Learn git bisect — it finds which commit introduced a bug in log(N) steps.

Keep reading

You may also like

Discussion (0)

No comments yet. Be the first to weigh in.

Leave a comment

Comments are reviewed before appearing.