5

I'm new to Github and I've been using the windows github tool which has proved a great help and handled a lot of things like SSH keys, prompts commits, discard a commit, revert commit, and it has a combined mechanism of pull+merge & push (sync), and a lot!

I'm learning it and trying to get its internal git command level executions. The other day, I merged a hotfix branch and then wanted to delete it -

git branch -d hotfix

I need to know how to delete it from the server as well. What are the git equivalents of the following two actions available in manage branch in the windows tool -

  • Unpublish a branch - remove only from the server
  • Delete a branch - remove locally and on server

Another thing I doubt is that the above git command was unable to remove the branch locally. I executed it, it removed the branch (didn't show in $ git branch) but if I restart the tool, the branch was still there! Was that a glitch?

If someone has been using these, can you pls suggest the best approach (I don't want to be totally dependent on the tool, I want to learn git as well).

Community
  • 1
  • 1
Hemant Tank
  • 1,724
  • 4
  • 28
  • 56

1 Answers1

5

In addition to

git branch -d hotfix

you also can remove it from GitHub:

git push origin --delete hotfix

You can see more at "How do I delete a Git branch both locally and in GitHub?"


If you have already deleted branches locally, a simple:

git push --prune origin

is enough to clean those same branches on your GitHub repo.


The opposite situation is when you have deleted branches on GitHub, while they are still on your local repo.
In that case:

git remote prune origin

See "cleaning up old remote git branches".

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • delete local doesn't work "error: Cannot delete branch 'xxx' checked out c:\users..... – user2568374 Jun 06 '18 at 19:19
  • @user2568374 Yes, you cannot delete a local branch which is *also* currently used (checked out). First checkout another branch. – VonC Jun 06 '18 at 19:54