Managing large-scale migrations in big monorepos with multiple codeowners can be overwhelming. Massive PRs touching thousands of files make it hard for teams to review changes efficiently.
codeowners-git (or cg for short) solves this by:
- Identifying files owned by specific teams using the CODEOWNERS file.
- Creating compact, team-specific branches with only their affected files.
- Streamlining the review process with smaller, targeted PRs.
Note: This tool works with unstaged files. Make sure to check if your files are unstaged before proceeding.
Screen.Recording.2025-01-28.at.10.37.05.PM.mov
Run commands directly without installation:
npx codeowners-git <command>npm install -g codeowners-gitThen run commands directly:
codeowners-git <command>
# or use the short alias
cg <command>The tool automatically detects CODEOWNERS files in:
.github/CODEOWNERSdocs/CODEOWNERSCODEOWNERS(root directory)
The --pr and --draft-pr options require the GitHub CLI (gh) to be installed and authenticated:
# Install GitHub CLI (macOS)
brew install gh
# Install GitHub CLI (Windows)
winget install --id GitHub.cli
# Install GitHub CLI (Linux)
sudo apt install gh
# Authenticate with GitHub
gh auth loginThe tool will automatically:
- Use PR templates if they exist in your repository (
.github/pull_request_template.md, etc.) - Set the PR title to your commit message
- Create PRs against the repository's default branch
Display the version of codeowners-git.
Usage:
codeowners-git --version
# or
codeowners-git -V
# or using the short alias
cg --versionList current CODEOWNERS entries.
Usage:
codeowners-git list [options]
# or
cg list [options]Options:
--owner, -oFilter by specific owner--include, -iInclude specific patterns
Example:
codeowners-git list -o @myteam
# or
cg list -o @myteamManage branch permissions in CODEOWNERS file.
Usage:
codeowners-git branch [options]
# or
cg branch [options]Options:
--owner, -oSpecify owner(s) to add/remove--branch, -bSpecify branch pattern--message, -mCommit message for changes--no-verify, -nSkips lint-staged and other checks before committing--push, -pPush branch to remote after commit--remote, -rRemote name to push to (default: "origin")--upstream, -uUpstream branch name (defaults to local branch name)--force, -fForce push to remote--keep-branch-on-failure, -kKeep the created branch even if operation fails--appendAdd commits to existing branch instead of creating a new one--prCreate a pull request after pushing (requires--pushand GitHub CLI)--draft-prCreate a draft pull request after pushing (requires--pushand GitHub CLI)
Example:
# Create a new branch
codeowners-git branch -o @myteam -b "feature/new-feature" -m "Add new feature" -p
# or
cg branch -o @myteam -b "feature/new-feature" -m "Add new feature" -p
# Create a branch and automatically create a pull request
cg branch -o @myteam -b "feature/new-feature" -m "Add new feature" -p --pr
# Create a branch and automatically create a draft pull request
cg branch -o @myteam -b "feature/new-feature" -m "Add new feature" -p --draft-pr
# Add more commits to the same branch later
cg branch -o @myteam -b "feature/new-feature" -m "Add more changes" --append -pCreate branches for all codeowners with changes.
Usage:
codeowners-git multi-branch [options]
# or
cg multi-branch [options]Options:
--branch, -bBase branch name (will be suffixed with codeowner name)--message, -mBase commit message (will be suffixed with codeowner name)--no-verify, -nSkips lint-staged and other checks before committing--push, -pPush branches to remote after commit--remote, -rRemote name to push to (default: "origin")--upstream, -uUpstream branch name pattern (defaults to local branch name)--force, -fForce push to remote--keep-branch-on-failure, -kKeep created branches even if operation fails--default-owner, -dDefault owner to use when no codeowners are found for changed files--ignoreComma-separated patterns to exclude codeowners (e.g., 'team-a,team-b')--includeComma-separated patterns to include codeowners (e.g., 'team-,@org/')--appendAdd commits to existing branches instead of creating new ones--prCreate pull requests after pushing (requires--pushand GitHub CLI)--draft-prCreate draft pull requests after pushing (requires--pushand GitHub CLI)
Note: You cannot use both
--ignoreand--includeoptions at the same time.
Example:
# Create branches for all codeowners
codeowners-git multi-branch -b "feature/new-feature" -m "Add new feature" -p
# or
cg multi-branch -b "feature/new-feature" -m "Add new feature" -p
# Create branches and automatically create pull requests for each
cg multi-branch -b "feature/new-feature" -m "Add new feature" -p --pr
# Create branches and automatically create draft pull requests for each
cg multi-branch -b "feature/new-feature" -m "Add new feature" -p --draft-pr
# Exclude specific teams
cg multi-branch -b "feature/new-feature" -m "Add new feature" --ignore "@ce-orca,@ce-ece"
# Include only specific patterns
cg multi-branch -b "feature/new-feature" -m "Add new feature" --include "@team-*"
# Use default owner when no codeowners found
cg multi-branch -b "feature/new-feature" -m "Add new feature" -d "@default-team"
# Add more commits to existing branches
cg multi-branch -b "feature/new-feature" -m "Add more changes" --append -pThis will:
- Find all codeowners for the staged files in your repository
- Apply any ignore/include filters if specified
- For each codeowner (e.g., @team-a, @team-b):
- Create a branch like
feature/new-feature/team-a - Commit only the files owned by that team
- Add a commit message like "Add new feature - @team-a"
- Push each branch to the remote if the
-pflag is provided
- Create a branch like
- Clone the repository
- Install dependencies:
bun install- Make your changes
- Run tests:
bun test- Submit a pull request
MIT ©