Home > Enterprise >  New / Merged / Deleted branches not updating
New / Merged / Deleted branches not updating

Time:11-08

So at my previous role, whenever someone created a branch in 'develop' I could refresh/ pull and the branch would appear in my VSC Source control. If a branch was deleted on GitHub, the branch also deleted (disappeared) in VSC. In this new repo, we work off of main and branches, more as a place to store code, rather than updating a website.

As you can see below, I deleted (on GitHub) these branches after the PR's were merged. They don't automatically disappear.

enter image description here

Furthermore, If someone else makes a branch from main, it will not appear in my list (as mine would not in theirs). Before this would be automatic. This is quite annoying as today for example, I made a branch in prep for another dev, and wanted them to just refresh 'branches' and switch to it.

I have tried git fetch, git remote update origin, prunes etc - nothing seems to work but manual updates and cloning branches from github.

Advice is really appreciated. Is it something to do with the repo setup?

Edit: New clone of the repo: branches don't show. I ran a git fetch and fetch --all but as you can see, nothing happened.

enter image description here

enter image description here

It might also be worth mentioning, if I open the repo on GitHub Desktop, I can see the branches, I can switch to the branch > open in VSC and then the branch is now displaying, allowing me to swap between main and said branch as expected.

Below is a screenshot of git branch --all enter image description here

CodePudding user response:

Based on the discussion in the comments, I think we've determined that things are working as expected, and the question arose due to a slight misunderstanding of the differences between local branches, and remote tracking branches.

There are many ways to conceptualize this, but I like to think of branches being in 1 of 3 buckets:

  1. Remote branches: branches that are on the remote repository now.
  2. Remote Tracking branches: your copy of #1 as of the last time you fetched (or pulled which includes a fetch, or cloned if you've never pulled or fetched since then).
  3. Local branches: branches that you have checked out locally and haven't deleted.

From your point of view, your repo on your machine is made up of buckets 2 and 3. Your file system as you see it is represented by the commit you have checked out now, which may be pointed to by one of your local branches, and if not, you are in "detached" mode.

When you clone a repository, you get a copy of the repo as it is at that moment. All of the branches that are on the server you cloned from (#1) are copied into your repo and stored as remote tracking branches (#2) These branches are prefixed by your remote name, typically origin. Also, when you clone, the default branch will be checked out as your only local branch (in your case the default branch is main) and is in bucket #3. You can view your branches with the commands:

git branch # view only your local branches
git branch -r # view only your remote tracking branches
git branch --all # view both your local and remote tracking branches

After a clone, if you use the command git branch --all you should see exactly one local branch, and all of the remote tracking branches that the repo has. Note that branches are simply pointers to a commit, and at that moment your local main will point to the same commit as origin/main.

Anytime you checkout an existing remote tracking branch for the first time, you create a new local branch pointer to that same commit. If you use the same name as an existing remote tracking branch but without the origin prefix, it will assume that's what you meant and track it for you. Otherwise you can create a new branch of any name you'd like, and point it to any commit you'd like.

So in the context of your question, here's what's happening:

  1. When you git fetch you connect to the remote server, and copy the latest branches from bucket 1 to bucket 2. This brings in new remote tracking branch names, and also updates existing ones that have moved to a different commit.
  2. When you git fetch --prune you do the same as number 1, but you also delete any remote tracking branches in your bucket #2 that have since been deleted in bucket #1.
  3. Nothing deletes any of your local branches in bucket #3, except for you.

Side Note: I think another source of confusion is that you are using both GitHub Desktop and VS Code and they display "branches" differently. GitHub Desktop lumps the branches in buckets #2 and #3 into the same list of branches (essentially git branch --all). VS Code on the other hand, separates the views, and puts local branches (bucket #3 using git branch) under "branches", and remote tracking branches (bucket #2 using git branch -r) under "remotes". This explains why you couldn't find all the branches in VS Code.

CodePudding user response:

I suspect you previously had automatic fetching settings enabled, but they are now disabled somehow. Check on the following settings:

  • git.autofetch
  • git.autofetchPeriod

git autofetch and git autofetch period settings

If you shared a settings.json file in your previous role, its possible that that "team" had these enabled, and now the settings.json file you are using in your new role has them disabled.

You may also need to enable git.pruneOnFetch as well.

  • Related