A cross-platform tool to clean up local Git branches that no longer exist on the remote repository. Available for both Unix-like systems (Linux/macOS) and Windows.
- Automatically detects and lists local branches that no longer exist on remote
- Prevents deletion of the current branch
- Interactive confirmation before deletion
- Option to skip confirmation
- Colored output for better visibility
- Cross-platform support (Bash and PowerShell)
-
Download the bash script directly:
# Using curl curl -O https://raw.githubusercontent.com/thiengo105/git-cleanup-branch/main/git-cleanup-branches # Or using wget wget https://raw.githubusercontent.com/thiengo105/git-cleanup-branch/main/git-cleanup-branches
-
Make the script executable:
chmod +x git-cleanup-branches
-
Move the script to a directory in your PATH:
sudo mv git-cleanup-branches /usr/local/bin/
-
Download the PowerShell script directly:
# Using PowerShell Invoke-WebRequest -Uri "https://raw.githubusercontent.com/thiengo105/git-cleanup-branch/main/git-cleanup-branches.ps1" -OutFile "git-cleanup-branches.ps1"
-
Create a PowerShell profile if you don't have one:
if (!(Test-Path -Path $PROFILE)) { New-Item -ItemType File -Path $PROFILE -Force }
-
Add the script to a directory in your PowerShell PATH (recommended location):
# Create the directory if it doesn't exist New-Item -ItemType Directory -Force -Path "$HOME\Documents\WindowsPowerShell\Scripts" # Move the script Move-Item -Path "git-cleanup-branches.ps1" -Destination "$HOME\Documents\WindowsPowerShell\Scripts"
-
Add an alias to your PowerShell profile:
Add-Content -Path $PROFILE -Value "Set-Alias -Name git-cleanup-branches -Value `"$HOME\Documents\WindowsPowerShell\Scripts\git-cleanup-branches.ps1`""
If you prefer to clone the entire repository:
# Clone the repository
git clone https://github.com/thiengo105/git-cleanup-branch.git
cd git-cleanup-branch
# For Unix-like systems
chmod +x git-cleanup-branches
sudo mv git-cleanup-branches /usr/local/bin/
# For Windows
# Follow steps 2-4 from the Windows installation above# Unix-like systems
git-cleanup-branches
# Windows
git-cleanup-branches# Unix-like systems
git-cleanup-branches -y
# Windows
git-cleanup-branches -y- The script first checks if you're in a Git repository
- Fetches and prunes remote-tracking branches
- Identifies local branches that no longer exist on remote
- Shows a list of branches to be deleted
- Prevents deletion if you're on a branch that would be deleted
- Asks for confirmation (unless -y flag is used)
- Deletes the branches and shows a summary
- Prevents deletion of the current branch
- Requires confirmation before deletion
- Shows clear warning messages
- Handles errors gracefully
- Git
- For Windows: PowerShell 5.1 or later
- For Unix-like systems: Bash shell
Feel free to submit issues and enhancement requests!
This project is licensed under the MIT License - see the LICENSE file for details.