lbranch ("last branch") is a git utility that shows your recently checked out branches in chronological order, with an optional interactive checkout.
# Show last 5 branches (default)
lbranch
# Show last N branches
lbranch -n 3
lbranch --number 3
# Show branches and select one to checkout
lbranch -s
lbranch --select
# Show last N branches and select one
lbranch -n 3 -s
# Color control
lbranch --no-color # Disable colored output
lbranch --force-color # Force colored output even in non-TTY environmentsLast 5 branches:
1) feature/new-ui
2) main
3) bugfix/login
4) feature/api
5) developlbranch automatically detects if your terminal supports colors:
- Colors are disabled when output is not to a terminal (when piped to a file or another command)
- Colors are disabled on Windows unless running in a modern terminal (Windows Terminal, VS Code, etc.)
- You can force colors on with
--force-coloror off with--no-color - lbranch respects the
NO_COLORandFORCE_COLORenvironment variables
lbranch follows the standard exit codes from sysexits.h for better integration with scripts and other tools:
- 0: Success
- 64: Command line usage error (not in a git repository, invalid selection)
- 66: Cannot open input (no branch history/no commits)
- 69: Service unavailable (git command not found)
- 75: Temporary failure (branch checkout failed, retry possible)
- 130: Operation interrupted (Ctrl+C)
These follow Unix conventions where exit codes 64-78 are standardized error codes, and 128+N indicates termination by signal N.
- Python 3.7+
- Git
You can install lbranch directly from PyPI:
pip install lbranchYou can install lbranch using Homebrew:
brew tap dcchuck/lbranch
brew install lbranchDistributed under the MIT License. See LICENSE