git-main
v0.5.0
Published
A CLI tool to manage git main/master branches and cleanup
Maintainers
Readme
git-main
Switch to main branch, clean up branches with deleted remotes, and handle dependencies - all in one command
Features
- 🔄 Auto-detects and switches to main/master branch
- 🧹 Cleans up branches with deleted remotes
- 🚦 Handles dirty working directory gracefully
- 📦 Auto-updates dependencies if lockfile changed
- 🎯 Supports yarn, pnpm, and npm
- ⚡️ Fast and lightweight
Installation
npm install -g git-mainOr use it directly with npx:
npx git-mainUsage
Simply run git-main in any git repository. The tool will:
- Switch to your main branch (auto-detects main/master)
- Clean up your working directory if needed
- Pull latest changes
- Remove branches with deleted remotes
- Update dependencies if lockfile changed (supports yarn, pnpm, and npm)
Package Manager Support
The tool automatically detects your package manager based on lockfiles:
yarn.lock→ usesyarn --immutablepnpm-lock.yaml→ usespnpm install --frozen-lockfilepackage-lock.json→ usesnpm ci
Example
$ git-main
ℹ Using main branch: main
→ Fetching latest changes...
→ Pulling latest changes...
→ Cleaning up branches with deleted remotes...
ℹ Deleting branch feature/123 (remote deleted)
ℹ Deleting branch fix/456 (remote deleted)
✓ Deleted 2 branches with deleted remotes
→ Installing dependencies with pnpm...
✓ All done! 🎉Running Tests
This project includes end-to-end (E2E) tests to ensure git-main behaves as expected in various scenarios.
End-to-End Tests
To run the E2E tests locally:
- Ensure you have Node.js installed. While the tool itself might run on older versions, the E2E tests specifically require Node.js 22.x.
Note: The E2E tests are configured to run on Node.js 22.x due to the use of the
--experimental-strip-typesflag. - Install dependencies:
npm install - Build the project:
npm run build - Run the tests:
npm run test
The tests will execute git-main in temporary Git repositories to simulate real-world usage.
License
MIT © Jan Nicklas
