The reason why I'm posting here today is because the behavior I see on the command line differs from what I actually read online. So it confuses me.
The two commands under question here are:
git branch -r -d origin/topic1
and
git push origin :topic1
My understanding so far (I may be completely wrong though, my brain is fried):
- The first should remove both the tracking reference and the remote branch
- The second should remove the remote branch but NOT the tracking reference (if a local branch exists), although the reason why you wouldn't remove the tracking reference seems pointless and confusing to me as a sort-of-beginner.
Here is a recent scenario I have run into. I just cloned a repository with two remote branches:
origin/master
origin/develop
The only local branch I have is:
master
I want to delete the remote branch origin/develop
, so watch this:
Robert@COMP /c/Code/project (master)
$ git branch -rd origin/develop
Deleted remote branch origin/develop (was 9ff16e8).
Robert@COMP /c/Code/project (master)
$ git fetch
From github.com:username/project
* [new branch] develop -> origin/develop
As you can see, I tried to delete the remote branch, and immediately fetch the latest changes from origin, but for some reason it recreated the branch. I have no idea why it would do this, I'm very confused. I don't have a local corresponding branch for origin/develop
, so I don't know why it is doing this.
I'd like to know why this happened, but also (to address the more general title of this question, and to perhaps help everyone else scavenging stack overflow for answers to these confusing ambiguities), I'd like more general answers to some questions:
- There are two ways to delete a remote branch. What is a really good, simple way to remember which one to use under which circumstance?
- Assuming it matters at all, how does the existence of a corresponding local branch (for a remote branch) affect the decision of how a remote branch is deleted?
- How does the existence of a tracking reference/relationship between a local and remote branch affect how you choose to delete a branch, and which of the methods of deleting a branch also cleans up tracking references?