Delete a git branch locally and remotely

+1 vote

I’m trying to delete a branch locally as well remotely but its giving errors

$ git branch -d remotes/origin/bugfix
error: branch 'remotes/origin/bugfix' not found.
$ git branch -d origin/bugfix
error: branch 'origin/bugfix' not found.
$ git branch -rd origin/bugfix
Deleted remote branch origin/bugfix (was 2a14ef7).
$ git push
Everything up-to-date
$ git pull
From github.com:gituser/gitproject
* [new branch] bugfix -> origin/bugfix
Already up-to-date.

What am I supposed to do?

Aug 17, 2018 in Git & GitHub by Hannah
• 18,550 points
2,098 views

2 answers to this question.

0 votes

Delete local branch

$ git branch -d branch_name
$ git branch -D branch_name

Delete remote branch

$ git push <remote_name> --delete <branch_name>

Then you should execute this on other machines

git fetch --all --prune

to propagate changes.

answered Aug 17, 2018 by Kalgi
• 52,310 points
0 votes

Deleting a remote branch:

git push origin --delete <branch>  # Git version 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 tracking branches
git fetch <remote> -p      # Shorter
answered Aug 20, 2018 by Nilesh
• 7,020 points

Related Questions In Git & GitHub

0 votes
1 answer

How to delete a Git branch remotely?

Hi@akhtar, You can delete the branch locally or ...READ MORE

answered Nov 21, 2020 in Git & GitHub by MD
• 95,140 points
80 views
0 votes
1 answer

How to do a re-merge into another branch in git

Seems like you want to rebase your ...READ MORE

answered May 7, 2018 in Git & GitHub by DareDev
• 6,890 points
874 views
0 votes
1 answer

Recovering a git branch

Check out the latest commit to this ...READ MORE

answered Nov 26, 2019 in Git & GitHub by Sirajul
• 59,030 points
150 views
0 votes
1 answer

error: The branch 'dev1' is not fully merged.If you are sure you want to delete it, run 'git branch -D dev1'.

Hi@akhtar, When you create one new branch in ...READ MORE

answered May 10, 2020 in Git & GitHub by MD
• 95,140 points
715 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 26, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
1,032 views
+2 votes
1 answer
0 votes
3 answers

difference between git remote and git clone

HI.... GIT REMOTE add just creates an entry in ...READ MORE

answered Jul 10, 2020 in Git & GitHub by anonymous
6,013 views
0 votes
1 answer

gerrit-cherry-pick:fatal: 'origin' does not appear to be a git repository

The user account making that command does ...READ MORE

answered Aug 13, 2018 in Git & GitHub by Kalgi
• 52,310 points
660 views