Hello Dev, In this blog we’ll give how to delete a git branch locally and remotely.
I want to delete a branch both locally and remotely. How to delete a Git branch locally and remotely?
$ 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.
Solution 1 Summary How to delete a Git branch locally and remotely?
$ git push -d <remote_name> <branchname>
$ git branch -d <branchname>
UseFul: In most cases to use, <remote_name>
will be origin
.
Delete Local Branch
to delete a local branch following sentense.
$ git branch -d <branch_name>
$ git branch -D <branch_name>
Solution 2:
Delete 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
Delete a local branch
git branch --delete <branch>
git branch -d <branch> # Shorter version
git branch -D <branch> # Force-delete all branches
