A powerful command-line tool designed to enhance your Git workflow with advanced commands tailored for developers. It simplifies complex Git operations, making branch management and navigation more efficient and intuitive.
branch:current
- Work with the current branchbranch:exists
- Check if the specified branch name existsbranch:freq
- List branches frequently checked outbranch:last
- Work with the last checked out branchbranch:recent
- List branches recently checked outbranch:search
- Search branch names for a substring or regex matchcheckout
- Check out a branch
Check out, then git pull
the main
branch:
git-ninja checkout main --pull
git-ninja co main -p
List recently checked out branches:
git-ninja branch:recent
List recently checked out branches, limit to 5 results and exclude 'develop' and 'main' from the list:
git-ninja branch:recent -c 5 -e 'develop|main'
Show the last checked out branch name:
git-ninja branch:last
Switch to the last checked out branch:
git checkout main
git checkout feature/my-feature
# switch from feature/my-feature to main:
git-ninja branch:last --checkout
Search for branches containing "fix":
git-ninja branch:search fix
Search for branches matching a regex pattern (e.g., all branches starting with GN-12
):
git-ninja branch:search -r "GN-12.+"
Search for a substring in branch names, and check out the first result:
git checkout main
git-ninja branch:search some-fix -o
# our active branch is now "feature/some-fix" (assuming that was the first result)
Add the following aliases to your .gitconfig
file to use git-ninja
commands as Git aliases:
[alias]
co = "!f() { git-ninja checkout $@; }; f"
# list recently checked out branches
lrb = "!f() { git-ninja branch:recent $@; }; f"
# list frequently checked out branches
lfb = "!f() { git-ninja branch:freq $@; }; f"
# search branches
sb = "!f() { git-ninja branch:search $@; }; f"
# push current branch
pcb = "!f() { git-ninja branch:current --push; }; f"
# switch to the last checked out branch
co-last = "!f() { git-ninja branch:last --checkout; }; f"
List recently checked out branches:
git lrb
Search branch names:
# find branches containing "fix"
git sb fix
# find branches matching a regex pattern
git sb -r "fix.+"
# find branches containing "fix" and check out the first result
git sb fix -o
# or checkout a branch by ticket number:
git sb -o 1123 # checks out 'GN-1123-my-feature-branch'
Switch to the last checked out branch:
git checkout main
git checkout feature/my-feature
git co-last # switch from feature/my-feature to main
The branch:recent
command can be run with the --jira
flag to slightly modify the ordering of the results based on open issues in JIRA. Assuming your branches contain
the JIRA issue key in the branch name, the command will rank branches with open issues that have been updated recently slightly higher in the list.
Tickets with a higher numerical suffix and have been recently updated are ranked slightly higher in the list, while tickets that have not been updated recently are ranked lower.
git-ninja branch:recent --jira
To enable the JIRA integration, set the JIRA_API_TOKEN
, JIRA_SUBDOMAIN
and JIRA_EMAIL_ADDRESS
environment variables.
go mod tidy
git-ninja
uses the task build tool. To build the project, run the following command:
task build
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.