jjmontes
jjmontes

Reputation: 26895

How to clean all data from a specific remote in git?

I have a git repo for which I use two different remotes:

$ git remote -v
origin  http://[email protected]/git/repo.git (fetch)
origin  http://[email protected]/git/repo.git (push)
origin-vpn  http://[email protected]/git/repo.git (fetch)
origin-vpn  http://[email protected]/git/repo.git (push)

This is the same upstream repository, but I must access it through different endpoints depending on where I am.

Now I don't often use origin-vpn, and it sometimes lags behind as I don't fetch from it normally. But when I look at my git log I see all branches and tags duplicated from both origins.

I'd like to clean all data from origin-vpn as if I had never fetched from it. I need the remote to exist as I may use it from time to time, but I don't want any refs from it to show up.

How can I do this? If there is no command for that, is it enough and safe to use git remote delete and git remote add again and would that remove all those refs?

Edit: This is how I see my git log:

alias gitlog='git log --color --graph --pretty=format:'\''%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'\'' --abbrev-commit'

Upvotes: 1

Views: 65

Answers (2)

Dolda2000
Dolda2000

Reputation: 25855

Just as an alternative: Since you state that you only pull from origin-vpn seldom, you may not actually need to set up a remote for it at all, in case you weren't already aware.

Functionally, a remote isn't really all that much more than an alias for a URL, and you can simply pull from the URL without setting up a remote for it:

git pull http://[email protected]/git/repo.git master

If you're actually planning to remove and recreate the origin-vpn remote every time you use it, then this seems simpler.

Upvotes: 1

g19fanatic
g19fanatic

Reputation: 10931

In order to remove a remote's refs from a local repository, you will need to do as you suggested and git remote rm origin-vpn. This will just remove the local copies of the remote and all of its references as well as configuration (upstream tracking branches).

At this point in time, I would immediately add the remote back but NOT fetch it. This will keep the vpn remote as a possible push/pull/fetch location (specifically by name) but not have any of its references clogging up your local repo.

So long as you do not set the upstream tracking branches to the vpn remote, a standard pull/fetch should only pull down the origin remotes refs and not the vpn.

Upvotes: 3

Related Questions