22 February 2022

Useful git commands

List config.
git config --list
git config --list --local
git config --list --global
git config --list --system
Set global name and email.
git config --global user.name "Your Name"
git config --global user.email "youremail@yourdomain.com"
Check what's going on
git status
Check changes made to a file
git diff path/to/file
Stage changes
# Stage all
git add .
# Stage one file
git add path/to/file
Untage changes
# Stage all
git reset
# Stage one file
git reset path/to/file
Revert changes made to path/to/file
git checkout path/to/file
Revert all uncommited changes
git checkout .
Commit staged files
git commit -m "Put a message here."
Check commits that had not been pushed.
git log origin/main..main
Check history of path/to/file
git log -p -- path/to/file