feature/profile-git-guide
New user-facing feature or page
Developer Notes
A practical reference for naming branches, saving work with stash messages, checking history, and keeping a branch ready for review.
feature/profile-git-guide
New user-facing feature or page
fix/navbar-mobile-spacing
Bug fix or broken UI behavior
chore/update-gems
Maintenance, tooling, cleanup, or config
refactor/extract-policy-service
Code restructuring without changing behavior
docs/git-cheatsheet
Documentation-only change
test/add-profile-system-test
Test-only or test-heavy change
Modern Git
`git checkout` is the older all-purpose command. `git switch` was added to make branch movement clearer, while `git restore` handles file recovery.
Prefer this when moving between branches or creating a new branch. It says exactly what you are doing.
git switch main
Go to an existing branch.
git switch -c feature/new-page
Create and move to a new branch.
When the job is to undo file edits or unstage files, `restore` is clearer than the old checkout style.
git restore app/models/user.rb
Discard edits in one file.
git restore --staged app/models/user.rb
Unstage but keep your changes.
You will still see `checkout` in tutorials and older projects. It can switch branches and restore files, which is why it can feel confusing.
git checkout main
Older way to switch branches.
git checkout -- app/models/user.rb
Older way to discard edits in a file.
Quick rule
For daily work: use `git switch` when changing branches, use `git restore` when undoing file changes, and only use `git checkout` when following older commands or when a repo guide specifically uses it.
Cheat Sheet
git status
See changed, staged, and untracked files.
git branch
List local branches.
git switch main
Move back to the main branch.
git pull --rebase
Update your current branch before starting work.
git switch -c feature/add-login
Create and switch to a new branch.
git branch -m feature/better-name
Rename the current branch.
git push -u origin feature/add-login
Push the branch and track it on origin.
git branch -d feature/add-login
Delete a local branch after it is merged.
git add app/views/profiles/git_cheatsheet.html.erb
Stage one file.
git add .
Stage all current changes.
git commit -m "Add Git cheat sheet page"
Commit staged changes with a clear message.
git diff --check
Catch whitespace issues before pushing.
git stash push -m "wip profile page polish"
Stash tracked changes with a readable message.
git stash push -u -m "custom description for stash"
Stash tracked and untracked files.
git stash list
Show saved stashes.
git stash show -p stash@{0}
Preview what is inside a stash.
git stash pop
Apply the latest stash and remove it from the stash list.
git stash apply stash@{1}
Apply a stash but keep it in the stash list.
git restore app/models/user.rb
Discard local changes in one file.
git restore --staged app/models/user.rb
Unstage a file but keep the edits.
git reset --soft HEAD~1
Undo the last local commit but keep its changes staged.
git commit --amend
Edit the previous commit before it is shared.
git revert <commit_sha>
Create a new commit that undoes an older commit.
git log --oneline --decorate --graph -12
Read the recent branch history.
git show <commit_sha>
Inspect one commit.
git diff main...HEAD
See everything your branch changes versus main.
git blame app/controllers/profiles_controller.rb
See who last changed each line.
Common Workflow
1. Update main
git switch main && git pull --rebase
2. Create branch
git switch -c feature/git-cheatsheet-page
3. Work and inspect
git status && git diff
4. Commit
git add . && git commit -m "Add Git cheat sheet page"
5. Push
git push -u origin feature/git-cheatsheet-page
6. Open PR
Compare your branch against main and describe the change.