This script allows you to delete a branch from both your local and remote Git repositories.
-
Make the script executable:
chmod +x delete-branch.sh
-
Run the script:
./delete-branch.sh
-
Follow the prompts:
- Enter the name of the branch you want to delete.
-
The script checks if the branch exists locally:
- If it does, the branch is deleted locally.
- If it does not, a message is displayed indicating the branch does not exist locally.
-
The script then checks if the branch exists remotely:
- If it does, the branch is deleted remotely.
- If it does not, a message is displayed indicating the branch does not exist remotely.
-
Output messages will indicate the status of the deletion process for both local and remote branches.
The script uses the following Git commands:
git show-ref
- Checks if the branch exists locally.git branch -D
- Deletes the branch locally.git ls-remote
- Checks if the branch exists remotely.git push --delete
- Deletes the branch remotely.
Be careful when deleting a branch, as this action cannot be undone. Ensure that you have committed all necessary changes and have a backup before running this script.