Reputation: 9
Delete remote branch commands:
Which is correct? Or what's the difference?
Upvotes: 0
Views: 1460
Reputation: 490068
The git remote
command is mostly for manipulating "remotes".
That's kind of circular:
git remote
?git remote
manipulates. 😀But in fact, a remote is a very specific thing in Git. It's a name, and under that name, Git keeps the URL of some other Git.
There is a bit more to it than that, but it's enough to get started: just remember, in Git, a remote is a name for the URL by which your Git calls up another Git. In effect, it's like a contact in your address-book in your phone. You don't have to remember Joe's phone number, you can just remember Joe's name.
Hence:
git remote delete origin
tells your Git: Forget the name origin
, and with it, the URL my Git uses to call up some other Git.
On the other hand, git push
has your GIt call up another Git. The syntax for this is git push remote-name stuff-to-do
. So git push origin
means: Hey, my Git! Call up another Git! Look up their "phone number" using the name origin
!
Once your Git calls up their Git, the two Gits will have a conversation. Your Git will send them stuff (if you ask your Git to do that), and then your Git will ask them to do things to their branches and/or tags. With:
git push origin --delete <branch-name>
you are telling your Git: Call the Git whose number is in the address book under the name origin
, and ask them to delete the branch I named here. So if your goal is to have them delete a branch named origin
, the command you want would be git push origin --delete origin
.
Upvotes: 0
Reputation: 29710
git push --delete origin <branchname>
This deletes a branch named <branchname>
from the remote repository.
From your question:
git push origin --delete origin
would delete the branch origin
.
This is quite destructive if other users are committing and pushing to that branch. All changes on that branch will be lost. You and all others working on that branch won't be able to push/pull to/from it again.
This removes the remote named <name>
from your local copy of the repo.
This is NOT for deleting a branch.
From your question:
git remote remove origin
would remove the remote origin
.
The remote is where you normally cloned the repo from, and is where you push/pull branches to/from. This is not as destructive to others as it only removes your origin
on your machine. But note that it can be destructive to you because "All remote-tracking branches and configuration settings for the remote are removed.".
Which is correct?
It depends on what you want to do. If you want to delete a remote branch, use git push --delete origin <branchname>
. Take note that you have to specify a <branchname>
and origin
is normally not a branch.
See this related post on deleting branches: How do I delete a Git branch locally and remotely?
Upvotes: 3
Reputation: 421
They are extremely different.
# lists all remotes you have added
git remote -v
# removes origin from your remotes
# doesn't delete anything in the remote repo
# you just wouldn't be able to git [fetch|pull] origin
# all local branches are kept
# just preventing yourself from reading from the remote repo and updating your local branches
git remote remove origin
# there's never a good reason to use this
# sounds like you're trying to delete a branch called origin on the origin remote
# makes no sense
git push origin --delete origin
Probably look into "git [branch|remote] --help"
Upvotes: 1