Garden Garden - 1 year ago 107
Git Question

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

I made a local branch, but then realized that I do not need it.

If I delete it from the local repo, will I have to delete from the remote, too? I just made that branch and did not add, commit or pushed anything into it - in short I did not do anything in it.

Answer Source

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

(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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download