Search code examples
gitgit-fetch

Does git have some kind of caching mechanism?


I am having a "weird" issue with Git on Windows and I am not sure if something has changed recently as for example a cache mechanism was added or kind off.

I have a branch locally: branch_A and that branch was deleted from the remote. How do I know? Because ...

  • I checked the Github PR and it was merged and the branch was deleted
  • I ran the command git branch -r | grep branch_A and no results were returned

For some reason the command:

git checkout master && git pull origin master && git fetch -p

Is not telling me all the branches that were deleted from the remote. In other words it shows some of the branches that were deleted from remote but miss some others that were deleted as well.

That leads me to end up with dead branches and making it hard for me to know which branches should I keep updated and I have to go through all the PR checking if the branch was deleted or not so I cleanup my local repository.

Note: I am not expecting the command to delete any branch locally it makes no sense because git does not know if I need it or not (as @Chris says on it's answer)

The version I am running of Git is: git version 2.23.0.windows.1.

Does any one have an idea of what could be wrong here? Am I missing something?


Solution

  • git fetch -p will only show you remote branches that were deleted and where you still got a reference to.

    git fetch -p should show you which remote branches were deleted; providing output like this:

     - [deleted]         (none)     -> origin/branch_A
    

    This will remove the reference origin/branch_A from your repository, but not your local branch branch_A.

    As you can see in this question there doesn't seem to be an easy answer for this. Reason is that git doesn't know for sure you don't need the branch anymore; it might have been out of sync with the remote branch that got deleted (and no more way to check this since the reference is gone now).