Skip to content

c4arl0s/git-branch-delete-ui

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

20 Commits
Β 
Β 
Β 
Β 

Repository files navigation

πŸ—‚οΈ Git Branch Delete UI

License: MIT Shell: Bash

An interactive tool to safely and easily delete Git branches

πŸ“– Description

git-branch-delete-ui.sh is a bash script that provides an intuitive graphical interface to delete Git branches interactively. The script uses dialog to create a user-friendly interface that allows you to select multiple branches and confirm their deletion before executing the action.

✨ Features

  • πŸ” Automatic detection: Automatically identifies all available branches
  • πŸ›‘οΈ Smart protection: Automatically excludes main, master branches and the current branch
  • βœ… Safety confirmation: Asks for confirmation before deleting selected branches
  • 🎯 Multiple selection: Allows selecting multiple branches to delete in a single operation
  • πŸ“Š Informative messages: Provides clear feedback with success, warning, and error messages
  • πŸ”„ Repository validation: Verifies that the current directory is a valid Git repository

πŸš€ Installation

Prerequisites

The script requires dialog for the graphical interface:

macOS

brew install dialog

Ubuntu/Debian

sudo apt-get install dialog

CentOS/RHEL

sudo yum install dialog

Setup

  1. Download the script:
curl -O https://raw.githubusercontent.com/c4arl0s/git-branch-delete-ui/main/git-branch-delete-ui.sh
  1. Make the script executable:
chmod +x git-branch-delete-ui.sh
  1. Optional: Add to PATH
# Add to ~/.bashrc or ~/.zshrc
export PATH="$PATH:/path/to/your/script"

πŸ“‹ Usage

Basic usage

./git-branch-delete-ui.sh

Example workflow

  1. Navigate to your Git repository:
cd /path/to/your/repository
  1. Run the script:
./git-branch-delete-ui.sh
  1. Select the branches:

    • The script will display a list of available branches
    • Use arrow keys to navigate
    • Press space to select/deselect branches
    • Press Tab to move between options
  2. Confirm deletion:

    • The script will ask for confirmation before deleting
    • Select "Yes" to proceed or "No" to cancel

πŸ–ΌοΈ Screenshot

Git Branch Delete UI Interface

πŸ”§ Script Features

Important branch protection

The script automatically excludes:

  • The current branch (where you're working)
  • The main branch
  • The master branch

System messages

  • πŸ”΄ Errors: Displayed in red with timestamp
  • 🟑 Warnings: Displayed in yellow with timestamp
  • 🟒 Success: Displayed in green when the operation is successful

Validations

  • βœ… Verifies that you're in a valid Git repository
  • βœ… Confirms that there are branches available to delete
  • βœ… Asks for confirmation before executing git branch -D

πŸ› οΈ Development

Code structure

# Configuration variables
readonly CURRENT_BRANCHES_MSG='Current Branches to remove, select them:'
readonly DIDNT_SELECT_BRANCH_MSG='You did not select any branch'
# ... more variables

# Main functions
error()          # Error handling
warning()        # Warning handling  
clean_branches() # Branch filtering
are_you_sure_msg() # User confirmation

# Main logic
# Repository validation β†’ Branch retrieval β†’ 
# Filtering β†’ User interface β†’ Confirmation β†’ Deletion

πŸ› Troubleshooting

Error: "dialog: command not found"

# Install dialog according to your operating system
brew install dialog  # macOS
sudo apt install dialog  # Ubuntu/Debian

Error: "Current directory is not a git repository"

# Make sure you're in a directory with a Git repository
cd /path/to/your/git/repository
git status  # Verify it's a valid repo

No branches appear to delete

  • Verify you have local branches (not just remote ones)
  • Make sure you're not on a branch without other local branches
  • The script excludes main, master and the current branch

πŸ“ License

This project is licensed under the MIT License. See the LICENSE file for more details.

🀝 Contributing

Contributions are welcome. Please:

  1. Fork the project
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ‘¨β€πŸ’» Author

Carlos Santiago Cruz

πŸ“š Additional Resources


⭐ Like this script? Give it a star!

About

BASH script git-delete-branches

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages