Git commands commonly used in production-based projects.
This cheat sheet is crafted to give you specific commands with clear purpose and practical context! 🧠💻🚀
git init
🔹 Purpose: Start a new Git repo
💡 Use case: When creating a brand-new project folder
git init
📁 Creates a .git
directory to track versions
git clone <repo_url>
🔹 Purpose: Copy a remote repo to your system
💡 Use case: Joining an existing project
git clone https://github.com/username/project.git
🧲 Pulls entire project + history
git status
🔹 Purpose: View file states (untracked/modified/staged)
git status
🕵️ See what's happening!
git add <file>
or git add .
🔹 Purpose: Stage changes for commit
git add index.html
git add . # Stage all changes
📌 Prepares files to be committed
git commit -m "message"
🔹 Purpose: Save a snapshot of staged changes
git commit -m "✨ Added login API"
📝 Creates a version with message
git log
🔹 Purpose: Show previous commits
git log
🕰️ Track what happened and when
git push
or git push origin <branch>
🔹 Purpose: Upload local commits to GitHub/GitLab
git push origin main
☁️ Make your work live on remote
git pull
🔹 Purpose: Fetch + merge from remote
git pull origin main
🔄 Get latest updates from team
git branch <name>
🔹 Purpose: Create a new feature branch
git branch feature/chat-ui
🧪 Use for isolated development
git checkout <branch>
🔹 Purpose: Switch branches
git checkout feature/chat-ui
🚦 Switch contexts easily
git checkout -b <branch>
🔹 Shortcut: Create + switch
git checkout -b hotfix/login-bug
git merge <branch>
🔹 Purpose: Merge target into current branch
git checkout main
git merge feature/chat-ui
🔗 Integrate features into production
When Git shows conflicts during merge:
# Edit conflicted files
git add .
git commit -m "🧹 Resolve merge conflict in config.js"
⚔️ Handle overlapping changes carefully
git stash
🔹 Purpose: Temporarily save dirty changes
git stash
git stash pop # To bring it back
🧳 Pack work-in-progress when you switch tasks
git reset
🔹 Purpose: Unstage or roll back commits
git reset HEAD~1 # Undo last commit (keep changes)
git reset --hard HEAD~1 # Delete last commit & changes
🧯 Careful with --hard
!
git tag <version>
🔹 Purpose: Mark releases
git tag v1.0.0
git push origin v1.0.0
🏷️ Useful for deployments
git remote -v
🔹 Check remotes:
git remote -v
git remote add origin <url>
🔹 Add remote:
git remote add origin https://github.com/username/project.git
🌐 Connect local repo to GitHub
git diff
🔹 Purpose: View changes
git diff # unstaged
git diff --staged # staged
🔍 Perfect for code reviews
git clean -fd
🔹 Purpose: Remove untracked files/directories
git clean -fd
🧹 Use carefully, irreversible!
.gitignore
🔹 Purpose: Ignore files/folders from tracking
📁 Example:
node_modules/
.env
*.log
🚫 Keeps secrets and junk out of repo
git config --global alias.st status
git config --global alias.cm "commit -m"
git config --global alias.co checkout
⚡ Save typing effort
🔐 Always use .gitignore
🌳 Use feature branching
💬 Meaningful commit messages
🧪 Test before pushing
👀 Code review with git diff
/ PR
🚀 Use git tag
for release cycles