In my current repo I have the following output:
$ git branch -a
* master
remotes/origin/master
remotes/public/master
I want to delete <
git push public :master
This would delete the remote branch named master
as Kent Fredric has pointed out.
To list remote-tracking branches:
git branch -r
To delete a remote-tracking branch:
git branch -rd public/master
I had a similar problem. None of the answers helped. In my case, I had two removed remote repositories showing up permanently.
My last idea was to remove all references to it by hand.
Let's say the repository is called “Repo”. I did:
find .git -name Repo
So, I deleted the corresponding files and directories from the .git folder (this folder could be found in your Rails app or on your computer https://stackoverflow.com/a/19538763/6638513).
Then I did:
grep Repo -r .git
This found some text files in which I removed the corresponding lines. Now, everything seems to be fine.
Usually, you should leave this job to git.
All you need to do is
git fetch -p
It'll remove all your local branches which are remotely deleted.
If you are on git 1.8.5+ you can set this automatically
git config fetch.prune true
or
git config --global fetch.prune true
All you need to do is
$ git branch -rd origin/whatever
It's that simple. There is no reason to call a gc here.
git gc --prune=now
is not what you want.
git remote prune public
or git remote prune origin
# if thats the the remote source
is what you want
You might be needing a cleanup:
git gc --prune=now
or you might be needing a prune:
git remote prune public
prune
Deletes all stale tracking branches under <name>. These stale branches have already been removed from the remote repository referenced by <name>, but are still locally available in "remotes/<name>".
With --dry-run option, report what branches will be pruned, but do no actually prune them.
However, it appears these should have been cleaned up earlier with
git remote rm public
rm
Remove the remote named <name>. All remote tracking branches and configuration settings for the remote are removed.
So it might be you hand-edited your config file and this did not occur, or you have privilege problems.
Maybe run that again and see what happens.
If you take a look in the revision logs, you'll note I suggested more "correct" techniques, which for whatever reason didn't want to work on their repository.
I suspected the OP had done something that left their tree in an inconsistent state that caused it to behave a bit strangely, and git gc
was required to fix up the left behind cruft.
Usually git branch -rd origin/badbranch
is sufficient for nuking a local tracking branch , or git push origin :badbranch
for nuking a remote branch, and usually you will never need to call git gc