oh-my-zsh plugin for managing branches
Updating branches can be a pain, especially if you have unsaved changes in your workspace. branch-manager
makes it easier to perform updates by auto-stashing your changes before doing routine maintenance, and then returning you to your workspace.
branch-manager
adds the following commands to your shell:
-
update_branch [branch=current_branch]
Pullbranch
and return to your workspace
You can also use this to update other branches while staying in your own -
merge_branch [branch=default_branch]
Mergebranch
into your own -
rebase_branch [branch=default_branch]
Rebasebranch
into your own -
pull_and_prune [branch=default_branch]
Pullbranch
and delete all dead/merged branches.
Useful for staying up-to-date with an active remote, while keeping your local repo tidy
For commands that default to the “default branch” (e.g. master
/main
), the default branch is determined by checking the following in order:
git config init.defaultBranch
BRANCH_MANAGER_DEFAULT_BRANCH
environment variable- …otherwise defaults to
master
If it’s guessing wrong, the easiest way to fix it is to set the default branch per repo:
git config init.defaultBranch [your_branch_name_here]
or globally:
git config --global init.defaultBranch [your_branch_name_here]
branch-manager
is built to work with oh-my-zsh, so you’ll need that installed first.
$ cd ~/.oh-my-zsh/custom/plugins
(you may have to create the folder)$ git clone git@github.com:elstgav/branch-manager.git
- In your .zshrc, add
branch-manager
to your oh-my-zsh plugins:
plugins(rails git branch-manager)
- Update
pull_and_prune
to detect and delete squash-merged branches
- Fix global namespace pollution by using local variables
- Auto-detect default branch name (see Determining Default Branch above)
- Add autocompletion of branch names
- Change
pull_and_prune
branch deletion message color
Changed from red (danger) to yellow (warning), since branch deletion is expected behavior.
- Add
pull_and_prune
command
- Colorize status messages
- Print message when restoring stashed changes
- Include untracked files when auto-stashing changes
- Remove “no stash” feedback to reduce noise
- Fix warning message if post-checkout hook doesn’t exist (#2)
- Add
rebase_branch
command (Thanks @blimmer!)