Deleting a local Git Branch that was never pushed - delete it on the server, too?

If you didn't push the branch to the remote, you can simple delete it locally:

git branch -d my_branch

Note: git will refuse to delete the branch if you have not merged it into its upstream or the current branch, to save you from losing the commits in the branch. If you are certain you do not need the commits, you can force the deletion with git branch -D my_branch.


You can get an overview of all branches by typing:

git branch -a

This may give something like the following:

*  master
   my_branch
   remotes/origin/master

(The branch with * is your current branch)

Note that the remote 'origin' doesn't have the local branch my_branch, since you haven't pushed it yet. Even if you had added and committed on the branch locally, it wouldn't be on the remote (until you push it).

If you did push it, you can remove it from the remote as follows:

git push origin :my_branch

It seems like you are from SVN background (though I am not sure completely). So here are the points. 1. Creating branch locally has nothing to do with remote until you pushed it.

  1. All you commit will reside in your local machine and will go to the remote only you push it.

So you can go ahead and delete the local branch if you are sure you no longer need it.

But you want double check if this local branch is have reference on remote then after delete you can run git fetch and then check if that branch still exist by executing command git branch --all


You need to type in your console

git branch -D myBranch


If the branch is only present in your local environment then just delete it by the following steps;

To get all the local branches;

git branch

the output will be like;

* your_local_branch (which you want to delete)
  master

Do git checkout master

And then to delete it locally,

git branch -d your_local_branch

If you want to delete the remote branch ( if the branch has been pushed to git repo )

git push origin :your_local_branch (if it is pushed)