Clean remotes/origin/master branch after deleting remote repository

1.3k views Asked by At

I have deleted my github repository but still want to keep versions on my local.

However, I still have remotes/origin/master branch when I run git branch -a.

I want to get rid of remote branches but when I try to;

git pull --prune

remote: Repository not found.
fatal: repository 'https://github.com/EfeBudak/InterestCalculator.git/' not found

How can I remove remote branches even if the remote repository does no longer exist?

2

There are 2 answers

4
Emilio Martinez On

You can use the git remote rm command:

$git remote rm [remote name]
2
noisy On

so... lets confirm, that in the beggining you have something like this:

noisy@t440s ~/devel/gitschool
$ git remote 
origin

noisy@t440s ~/devel/gitschool
$ git remote -v
origin  [email protected]:noisy/gitschool.git (fetch)
origin  [email protected]:noisy/gitschool.git (push)

noisy@t440s ~/devel/gitschool
$ git remote add backup [email protected]:noisy/gitschool_backup.git

$ git remote -v
origin  [email protected]:noisy/gitschool.git (fetch)
origin  [email protected]:noisy/gitschool.git (push)
backup  [email protected]:noisy/gitschool_backup.git (fetch)
backup  [email protected]:noisy/gitschool_backup.git (push)

... and later

noisy@t440s ~/devel/gitschool
$ git fetch --all
Fetching origin
remote: Counting objects: 44, done.
remote: Compressing objects: 100% (44/44), done.
remote: Total 44 (delta 18), reused 0 (delta 0)
Unpacking objects: 100% (44/44), done.
From myserver.com:noisy/gitschool
 * [new branch]      T16 -> origin/T16
Fetching backup
From myserver.com:noisy/gitschool_backup
 * [new branch]      T16 -> backup/T16
 * [new branch]      master     -> backup/master

and finally you have deleted your backup repository... but git branch -r still gives:

noisy@t440s ~/devel/gitschool
$ git branch -r
  origin/HEAD -> origin/master
  origin/T16
  origin/master
  backup/T16
  backup/master

In my case, after removing remote backup...

noisy@t440s ~/devel/gitschool
$ git remote rm backup

I see only branches on my current remote :)

noisy@t440s ~/devel/gitschool
$ git branch -r
  origin/HEAD -> origin/master
  origin/T16
  origin/master