Delete Git Remote and Local Branch
Table of Contents
git --version
# git version 2.34.1
Delete remote branch:
git branch -d <remote> <branch>
git branch --delete <remote> <branch>
git push <remote> :<branch>
# For example:
git branch -d origin feature/foo
git branch origin :future/foo
git --help push
# OPTIONS
# -d, --delete
# All listed refs are deleted from the remote repository. This is the same as prefixing all refs with a colon.
Delete local branch
git branch -d <branch>
git branch --delete <branch>
git branch -D <branch>
git branch --delete --force <branch>
git --help branch
# OPTIONS
# -d, --delete
# Delete a branch. The branch must be fully merged in its upstream branch, or in HEAD if no upstream was set with --track or --set-upstream-to.
# -D
# Shortcut for --delete --force.
# -f, --force
# Reset <branchname> to <startpoint>, even if <branchname> exists already. Without -f, git branch refuses to change an existing branch. In combination with -d (or --delete), allow deleting the
# branch irrespective of its merged status, or whether it even points to a valid commit. In combination with -m (or --move), allow renaming the branch even if the new branch name already exists,
# the same applies for -c (or --copy).