Git Cheat Sheet

Common Git commands for version control and teamwork.

Configuration

Concept / Tag Code Snippet Description
Set Name
git config --global user.name "Your Name"
Identity setup.
List Config
git config --list
View all settings.

Remote Basics

Concept / Tag Code Snippet Description
Add Remote
git remote add origin url
Connect to GitHub.
Upstream
git push -u origin main
Track remote branch.

Stash & Log

Concept / Tag Code Snippet Description
List Stash
git stash list
View saved work.
Log Graph
git log --oneline --graph --all
Visual history.

Fixing Mistakes

Concept / Tag Code Snippet Description
Amend Commit
git commit --amend -m "new msg"
Fix last commit.
Reset Work
git reset --soft HEAD~1
Remove commit, keep code.

Frequently Asked Questions

You can use "git reset --soft HEAD~1" to undo the commit but keep your changes, or "--hard" to discard everything.

Explore More Cheat Sheets