Skip to Content
sudocs

Staging and commits

how to stage changes and write commits that actually make sense

staging and commits

git add .

stages everything in the current directory. convenient but be careful — use git status first so you don't accidentally add junk.

git add -p

interactive staging. goes through each diff hunk and asks if you want to stage it. good when you've changed a bunch of stuff and want clean, focused commits instead of one giant blob.

git commit -m "your message here"

basic commit. write messages that describe why, not just what.

git commit --amend

rewrites the last commit. use it to fix a typo in your message or add a file you forgot. don't amend after you've pushed unless you're okay with force-pushing.

git stash

shelves your current changes so you can switch context. nothing gets committed, just saved off to the side.

git stash pop

brings those changes back. if you have multiple stashes, git stash list shows them and git stash pop stash@{1} lets you pick one.

On this page