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,520 points
3,524 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,350 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,060 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,460 points
748 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
2,453 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,230 points
1,256 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,460 points
3,085 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 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,019 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 11, 2020 in Git & GitHub by anonymous
23,405 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,350 points
1,935 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP