🧾Git & GitHub Cheat Sheet
📁 Setup Commands
Command Description
git --version Check installed Git version
git config --global user.name "Your Name" Set your Git username
git config --global user.email "[email protected]" Set your Git email
git config --list View current config
📂 Repository Commands
Command Description
git init Initialize a new local Git repo
git clone <repo-url> Clone an existing remote repo
📝 Basic Workflow
Command Description
git status Check current repo status
git add <file> Stage a specific file
git add . Stage all changes
git commit -m "message" Commit changes with a message
git push Push commits to remote
git pull Pull latest changes from remote
git log View commit history
🌿 Branching
Command Description
git branch List all branches
git branch <branch-name> Create a new branch
git checkout <branch-name> Switch to a branch
git checkout -b <branch> Create and switch to new branch
git merge <branch> Merge another branch into current
git branch -d <branch> Delete a branch (if merged)
🧠 Undo & Reset
Command Description
git reset <file> Unstage a file
git checkout -- <file> Discard local changes to file
git revert <commit> Undo a commit by creating a new one
git reset --hard <commit> Reset everything to a specific commit ⚠️
🔗 Remote Repositories
Command Description
git remote -v View remote repo URL(s)
git remote add origin <url> Add remote repo
git push -u origin main Push local to remote first time
🧰 Other Useful Commands
Command Description
git stash Temporarily save changes
git stash pop Apply latest stashed changes
git diff Show changes not yet staged
📌 Tips:
Always pull before you push.
Use meaningful commit messages.
Create feature branches for separate tasks.