Some text some message..
Back πŸ”„Git commands: Production-based projects πŸ§ πŸ’»πŸš€ 27 May, 2025

Git commands commonly used in production-based projects.
This cheat sheet is crafted to give you specific commands with clear purpose and practical context! 🧠💻🚀


🌱 1. Project Initialization

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


📦 2. Clone a Repository

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


🔄 3. Check Status & Changes

git status

🔹 Purpose: View file states (untracked/modified/staged)

git status

🕵️ See what's happening!


📤 4. Add Files to Staging

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


✅ 5. Commit Changes

git commit -m "message"

🔹 Purpose: Save a snapshot of staged changes

git commit -m "✨ Added login API"

📝 Creates a version with message


🔍 6. View Commit History

git log

🔹 Purpose: Show previous commits

git log

🕰️ Track what happened and when


🚀 7. Push to Remote

git push or git push origin <branch>

🔹 Purpose: Upload local commits to GitHub/GitLab

git push origin main

☁️ Make your work live on remote


📥 8. Pull Changes

git pull

🔹 Purpose: Fetch + merge from remote

git pull origin main

🔄 Get latest updates from team


🌿 9. Branching

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

🔀 10. Merging Branches

git merge <branch>

🔹 Purpose: Merge target into current branch

git checkout main
git merge feature/chat-ui

🔗 Integrate features into production


⚠️ 11. Resolve Conflicts

When Git shows conflicts during merge:

# Edit conflicted files
git add .
git commit -m "🧹 Resolve merge conflict in config.js"

⚔️ Handle overlapping changes carefully


🧼 12. Stash Work

git stash

🔹 Purpose: Temporarily save dirty changes

git stash
git stash pop  # To bring it back

🧳 Pack work-in-progress when you switch tasks


💣 13. Undo/Reset

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!


🧾 14. Tagging Releases

git tag <version>

🔹 Purpose: Mark releases

git tag v1.0.0
git push origin v1.0.0

🏷️ Useful for deployments


👯 15. Remote Management

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


🧮 16. View Differences

git diff

🔹 Purpose: View changes

git diff                 # unstaged
git diff --staged        # staged

🔍 Perfect for code reviews


👌 17. Clean Untracked Files

git clean -fd

🔹 Purpose: Remove untracked files/directories

git clean -fd

🧹 Use carefully, irreversible!


🔐 18. Gitignore Setup

.gitignore

🔹 Purpose: Ignore files/folders from tracking
📁 Example:

node_modules/
.env
*.log

🚫 Keeps secrets and junk out of repo


📚 19. Useful Git Aliases (Bonus 💡)

git config --global alias.st status
git config --global alias.cm "commit -m"
git config --global alias.co checkout

Save typing effort


🎯 Best Practices in Production

🔐 Always use .gitignore
🌳 Use feature branching
💬 Meaningful commit messages
🧪 Test before pushing
👀 Code review with git diff / PR
🚀 Use git tag for release cycles