Avoid Pushing to Main with Git Worktrees

VS Code showed I was on a feature branch. But Git pushed to main. Why? Ever faced this? You’re on the “right” branch Everything looks clean You push… …and it lands in main/staging 😐 Here’s what’s actually happening: 1. You’re not on the wrong branch   You’re in the wrong "folder" 2. Tools like Claude Code / Copilot CLI now use "Git worktrees" 3. That means:   • Same repo   • Multiple folders   • Each folder = different branch 4. VS Code shows branch state   Git uses your "current directory" 💥 Result: Right command. Wrong place. 🔒 Fix (this alone saves you): Before every push: `git status` Optional but powerful: • `pwd` • `git branch -vv` If it doesn’t match your expectation → don’t push. Most Git mistakes aren’t about Git. They’re about context. If you're using AI tools and haven't thought about worktrees yet… you will. Usually right after your first “push to main” moment. 👇 Full breakdown in comments #Git #SoftwareEngineering #WebDevelopment #AItools #DeveloperTips #Git #DevTools #SoftwareEngineering #Programming #DeveloperLife

  • Bold centered text “WHAT THE HELL ARE GIT WORKTREES???” over a split background showing chaotic red on the left and clean green on the right, symbolizing confusion vs clarity in Git workflows.

To view or add a comment, sign in

Explore content categories