TalkativeTurtles
[Tutorial] Essential Git commands and workflows every developer should know - Printable Version

+- TalkativeTurtles (https://talkativeturtles.club)
+-- Forum: Community (https://talkativeturtles.club/forumdisplay.php?fid=25)
+--- Forum: Tutorials & Resources (https://talkativeturtles.club/forumdisplay.php?fid=26)
+--- Thread: [Tutorial] Essential Git commands and workflows every developer should know (/showthread.php?tid=69)



[Tutorial] Essential Git commands and workflows every developer should know - Zero Two - 06-22-2026

Git is one of those tools where most people learn just enough to get by and then stay at that level forever. Here's a reference for the commands that go beyond the basics and are worth knowing.

The stuff everyone knows
Code:
git clone, git add, git commit, git push, git pull

Branching properly
Code:
git switch -c feature/my-feature    # create and switch to new branch
git switch main                       # go back to main
git branch -d feature/my-feature      # delete branch after merge

Staging selectively
Code:
git add -p    # interactively choose hunks to stage (very useful)

Fixing mistakes
Code:
git restore --staged file.txt    # unstage a file
git restore file.txt              # discard local changes to a file
git commit --amend --no-edit      # add staged changes to the last commit without changing the message
git reset HEAD~1                  # undo the last commit but keep the changes staged

Investigating history
Code:
git log --oneline --graph --all    # visual branch history
git log -p file.txt                # full history of changes to a file
git blame file.txt                 # who changed each line and when
git diff main...feature            # what changed on feature branch since it diverged from main

Finding regressions
Code:
git bisect start
git bisect bad HEAD           # current commit is broken
git bisect good v1.2.0        # this version was fine
# git tests each midpoint, you mark good/bad until it finds the commit

Stashing work in progress
Code:
git stash                     # save dirty working tree
git stash list                 # see all stashes
git stash pop                  # restore most recent stash

Cleaning up
Code:
git clean -fd                  # delete untracked files and directories (careful - irreversible)

A good Git mental model: commits are snapshots, branches are pointers to commits, and most "scary" commands (reset, rebase) just move these pointers around. Once that clicks, the tool becomes much less mysterious.