A set of helper scripts for the Git command line designed to automate repetitive tasks and keep your repository clean.
To ensure portability across different machines and operating systems without hardcoding paths, this repository includes setup scripts that register the installation directory as an environment variable (GIT_HELPERS).
Clone the repository and run the Bash installation script. This will add the GIT_HELPERS variable to your .bashrc or .profile.
git clone [https://github.com/bernardbr/git-helpers.git](https://github.com/bernardbr/git-helpers.git)
cd git-helpers
chmod +x install-env.sh
./install-env.shApply the changes:
source ~/.bashrcClone the repository and run the Zsh installation script optimized for macOS. This will add the GIT_HELPERS variable to your .zshrc.
git clone [https://github.com/bernardbr/git-helpers.git](https://github.com/bernardbr/git-helpers.git)
cd git-helpers
chmod +x install.zsh
./install.zshApply the changes:
source ~/.zshrcClone the repository and run the PowerShell installation script. Instead of a shell rc file, it registers GIT_HELPERS as a User environment variable (persisted in the registry, no admin rights required), so it is visible to git.exe and Git Bash from any terminal.
git clone https://github.com/bernardbr/git-helpers.git
cd git-helpers
./install-env.ps1If script execution is blocked by the current policy, run it for this session only:
powershell -ExecutionPolicy Bypass -File .\install-env.ps1The variable is set in the current session automatically. Other terminals and applications pick it up after being restarted.
Note: the helper scripts are Bash scripts, so Git for Windows (which ships with Git Bash) must be installed — the
!bash ...aliases below work as-is.
Once the GIT_HELPERS variable is set, you can configure your global .gitconfig using the variable. This approach works natively on Linux, macOS, WSL, and Windows (Git Bash resolves $GIT_HELPERS at runtime).
Open your global config (git config --global -e) and paste the following block:
[alias]
# Deletes local branches that are gone on the remote
delete-stale-branches = !bash "$GIT_HELPERS"/delete-stale-branches.sh
# Renames current branch locally and on remote
rename = !bash "$GIT_HELPERS"/rename-branch.sh
# Shows the latest tag
last-tag = !bash "$GIT_HELPERS"/show-last-tag.sh
# Deletes local tags that are gone on the remote
delete-stale-tags = !bash "$GIT_HELPERS"/delete-stale-tags.shAlternatively, you can run these commands one by one:
git config --global alias.delete-stale-branches '!bash "$GIT_HELPERS"/delete-stale-branches.sh'
git config --global alias.rename '!bash "$GIT_HELPERS"/rename-branch.sh'
git config --global alias.last-tag '!bash "$GIT_HELPERS"/show-last-tag.sh'
git config --global alias.delete-stale-tags '!bash "$GIT_HELPERS"/delete-stale-tags.sh'On PowerShell, use double quotes with the $ escaped so PowerShell does not expand it:
git config --global alias.delete-stale-branches "!bash `"`$GIT_HELPERS`"/delete-stale-branches.sh"
git config --global alias.rename "!bash `"`$GIT_HELPERS`"/rename-branch.sh"
git config --global alias.last-tag "!bash `"`$GIT_HELPERS`"/show-last-tag.sh"
git config --global alias.delete-stale-tags "!bash `"`$GIT_HELPERS`"/delete-stale-tags.sh"Checks for all local branches that no longer exist on the server (remote) and deletes them.
- Usage:
git delete-stale-branches
Renames both the local and remote branches while maintaining tracking.
- Usage:
git rename <new-branch-name>
Displays the latest tag created in the current tree.
- Usage:
git last-tag
Syncs your local tags with the remote, removing tags locally that were deleted on the server.
- Usage:
git delete-stale-tags
Made with ❤️ by Bernardo