karlncreate
karlncreate

Reputation: 65

How do I remove duplicate git remotes from local ist?

I was playing around with pushing the same project folder to different repos (GitHub and GitLab) and ended up renaming it into a bunch of different names.

Now how do I remove remotes with name like 'upstream' and 'origin' from my list generated when I use git branch -a?

WHAT A MESS OF A LIST: screenshot showing many branches

Upvotes: 0

Views: 597

Answers (1)

torek
torek

Reputation: 488003

In general, to add, update, or remove any given remote, you use the git remote command. The default action for git remote is to list the current set of remotes, so:

git remote

should list:

GitHub
GitLab
origin
upstream

given the set of remote-tracking names. To remove all but, say, origin, you could use:

git remote remove GitHub
git remote remove GitLab
git remote remove upstream

Note that git remote remove can only remove one remote at a time, so if you have a long list of remotes to remove, you might use a shell loop:

for i in GitHub GitLab upstream; do git remote remove $i; done

(assuming you are using sh or bash or anything compatible with those).

Note that git remote remove also removes the corresponding remote-tracking names. (Git calls these remote-tracking branch names, but I find the word branch here to be more confusing than helpful, so I recommend deleting it from the phrase.)

Upvotes: 1

Related Questions