How to delete a Git branch locally and remotely?

· · 373 views

I want to delete the git branch locally and remotely, but I don't know how? Here are my failed attempts:

Attempt 1:

git branch -d remotes/origin/bugfix

Output: error: branch 'remotes/origin/bugfix' not found.

Attempt 2:

git branch -d origin/bugfix

Output: error: branch 'origin/bugfix' not found.

Attempt 3:

git branch -rd origin/bugfix

Output: Deleted remote branch origin/bugfix (was 2a14ef7).

git push

Output: Everything up-to-date

git pull

Output: * [new branch] bugfix -> origin/bugfix

What should I do to delete the remotes/origin/bugfix branch both locally and remotely?

0
2 Answers

To remove a local branch from your machine:

git branch -d {the_local_branch} (use -D instead to force deleting the branch without checking merged status)

To remove a remote branch from the server:

git push origin --delete {the_remote_branch}

0

Deleting a remote branch

git push origin --delete <branch>  # Git version 1.7.0 or newer
git push origin -d <branch>        # Shorter version (Git 1.7.0 or newer)
git push origin :<branch>          # Git versions older than 1.7.0

Deleting a local branch

git branch --delete <branch>
git branch -d <branch> # Shorter version
git branch -D <branch> # Force-delete un-merged branches

Deleting a local remote-tracking branch

git branch --delete --remotes <remote>/<branch>
git branch -dr <remote>/<branch> # Shorter

git fetch <remote> --prune # Delete multiple obsolete remote-tracking branches
git fetch <remote> -p      # Shorter
0

Please login or create new account to participate in this conversation.