Worktree & Branch Management
repos provides three convenience commands for managing Git worktrees and keeping multi-branch projects in sync.
repos add_branch
Create a new worktree (or branch) off the current repository and wire it into the project scaffolding in one step:
repos add_branch <branch-name> [target-directory]The command:
- Creates a new worktree at
../<repo>-<branch>(or../<target-directory>) - Pushes the branch to
originwith tracking set up - Cleans the worktree (keeps only
.devcontainer/devcontainer.jsonand.gitignore) - Promotes
.devcontainer/prebuild/devcontainer.json→.devcontainer/devcontainer.json - Strips the Codespaces
repositoriesconfig fromdevcontainer.json - Appends an
@<branch>line torepos.list - Refreshes the VS Code workspace file
The resulting worktree can be opened independently in VS Code or Codespaces.
Options
| Flag | Description |
|---|---|
<branch-name> |
Name of the new branch to create (required) |
[target-directory] |
Custom directory name (default: <repo>-<branch>) |
-b, --branch |
Create as a plain branch instead of a worktree (not recommended) |
Examples
# Create a worktree at ../MyProject-data-tidy
repos add_branch data-tidy
# Create a worktree at a custom location
repos add_branch analysis my-analysis
# Create as a branch rather than a worktree
repos add_branch paper --branchNotes
- Worktrees share
.gitwith the base repository — saves disk space and simplifies fetching. - A branch can only be checked out in one worktree at a time.
- To remove a worktree:
git worktree remove <path>
repos update_branches
Propagate the latest devcontainer prebuild configuration from the base repository to every worktree:
repos update_branchesThe command:
- Reads
.devcontainer/prebuild/devcontainer.jsonfrom the base repository - Strips the Codespaces
repositoriessection - Writes the result to
.devcontainer/devcontainer.jsonin each worktree - Commits and pushes the changes in each worktree
Options
| Flag | Description |
|---|---|
-n, --dry-run |
Show what would be done without making changes |
Examples
# Update all worktrees
repos update_branches
# Preview changes without applying them
repos update_branches --dry-runPrerequisites
.devcontainer/prebuild/devcontainer.jsonmust exist in the base repository.jqorpython3must be available for JSON manipulation.
repos update_scripts
Pull the latest helper scripts from the upstream CompTemplate repository:
repos update_scriptsThe command:
- Clones / pulls the latest
MiguelRodo/CompTemplaterepository - Copies all scripts from its
scripts/directory (includinghelper/) - Preserves executable permissions
- Creates a git commit with the updates
Options
| Flag | Description |
|---|---|
-b <name>, --branch <name> |
Use a specific upstream branch (default: main) |
-n, --dry-run |
Show what would be updated without making changes |
-f, --force |
Overwrite local changes without prompting |
Environment variables
| Variable | Description |
|---|---|
UPSTREAM_BRANCH |
Override the default upstream branch |
Examples
# Update from the default (main) branch
repos update_scripts
# Update from a specific branch
repos update_scripts --branch dev
# Preview what would change
repos update_scripts --dry-run
# Force-overwrite local modifications
repos update_scripts --force