# Rename current branch git branch -m new-branch-name
Commit Best Practices
Write meaningful commit messages:
1 2 3 4 5 6 7 8 9 10 11 12
# Good commit message format git commit -m "feat: add user authentication - Implement JWT token generation - Add login and logout endpoints - Create user session middleware"
# Amend last commit git commit --amend
# Interactive staging git add -p
Stashing Changes
Save work in progress:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
# Stash current changes git stash save "WIP: working on feature X"
# List all stashes git stash list
# Apply most recent stash git stash apply
# Apply and remove stash git stash pop
# Apply specific stash git stash apply stash@{2}
# Clear all stashes git stash clear
Rebase vs Merge
Keep history clean with rebase:
1 2 3 4 5 6 7 8 9 10 11 12
# Update feature branch with main git checkout feature/my-feature git rebase main
# Interactive rebase to clean up commits git rebase -i HEAD~3
# Continue after resolving conflicts git rebase --continue
# Abort rebase git rebase --abort
Useful Aliases
Add these to your .gitconfig:
1 2 3 4 5 6 7 8 9
[alias] st = status co = checkout br = branch ci = commit unstage = reset HEAD -- last = log -1 HEAD visual = log --graph --oneline --all amend = commit --amend --no-edit