-1

Should 'git fetch' retrieve the same metadata about remote branches in all instances?

If I run ...

git fetch
git branch -r

... on several servers (environments) that have the same remote origin, should the output be the same? I'm asking because it's not the same, and I don't know why. It's close, but not identical. I'm trying to get all environments synced with regard to what branches exist on the remote origin. In one environment, 'git branch -r' displays a branch that (I think) no longer exists on the remote origin.

Why aren't they the same?

Which output from 'git branch -r' should I believe?

How do I get the metadata about remote branches synced?

For the record, I also tried ...

git fetch origin
git branch -r

... and that didn't help. I'm not sure if adding 'origin' to the fetch matters in this situation. I'm a git newbie.

Many thanks,

David

David.Woosley
  • 39
  • 1
  • 5
  • Do you need to `git pull`? I think 'git fetch' will just tell you what has changed between that remote environment and what you have locally. One you 'git pull' each of the different local environments, then they should all match. Or are you saying at that point they still don't match? – Cardi DeMonaco Jr Oct 29 '21 at 15:39
  • By default, `git fetch` does not _remove_ any tracking branches which no longer exist remotely. – IMSoP Oct 29 '21 at 15:39
  • 2
    @CardiDeMonacoJr "git pull" won't change which _branches_ are shown, only which _commits_ are on branches – IMSoP Oct 29 '21 at 15:41
  • 2
    Try `git fetch --prune` and then compare the difference. Or remove the local repo copy and clone again. – fredrik Oct 29 '21 at 15:41
  • 1
    Sorry, I linked the wrong duplicate. This one is more relevant: https://stackoverflow.com/questions/7726949/remove-tracking-branches-no-longer-on-remote or this one: https://stackoverflow.com/questions/3184555/cleaning-up-old-remote-git-branches Also, this one: https://stackoverflow.com/questions/20106712/what-are-the-differences-between-git-remote-prune-git-prune-git-fetch-prune and this one: https://stackoverflow.com/questions/18308535/automatic-prune-with-git-fetch-or-pull – IMSoP Oct 29 '21 at 15:42
  • Thanks @fredrik . – David.Woosley Oct 29 '21 at 16:16

1 Answers1

-1

As suggested above, this worked:

git remote prune origin

My question was a duplicate. My bad.

Thanks to all.

David.Woosley
  • 39
  • 1
  • 5