Create a local branch with git:

git branch **name**

Push this branch up to the remote, so it has it:

git push origin **name**

The local branch does not track the remote branch, however. I recall seeing a command to achieve this but I have forgotten it. You can, however, do

git branch -d **name**
git checkout --track -b **name** **origin/name**

Deleting remote branches only works locally: they come back.

git branch -r -d origin/foo
git push
git pull
* [new branch]      foo        -> origin/foo

The correct command?

git push origin :name

I think the ':' there is actually a range or mapping operator and you are saying "map nothing onto branchname name"... but I wouldn't have guessed that in a million years. I fully expect that if I read up on the internals a bit more, I will see what is going on... but from a VCS perspective, this is pretty unintuitive.

I actually wonder the wisdom of deleting remote branches. I locally branch quite a lot in order to try out invasive changes and have an easy back out (or easy "go away and do something else" when things don't go according to plan). I also push such branches up to the remote repository so I can access my work in progress from multiple computers. Most of my branches reach a point where the feature or change is merged and the branch has no further purpose. This is why I delete them: so the set of branches at a given point in time represents active work.

However, in theory it might be interesting to separate out the commits that relate to implementing a change at some point in the future, when performing some kind of code archaeology. You can generally think of a branch as a timeline, but the set of branches does not appear to be a timeline: once deleted, it's gone never to return.


I found the git publish-branch command a while back ( for the pushing-a-new-branch-to-a-remote problem. It pushes the branch and then does the config so that git pull works. If you just drop it somewhere in your path, "git publish-branch" just works. -- Evan