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.
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.
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.
2
Answers
I suspect you previously had automatic fetching settings enabled, but they are now disabled somehow. Check on the following settings:
git.autofetch
git.autofetchPeriod
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.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:
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 ismain
) and is in bucket #3. You can view your branches with the commands: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 localmain
will point to the same commit asorigin/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:
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.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.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 usinggit branch
) under "branches", and remote tracking branches (bucket #2 usinggit branch -r
) under "remotes". This explains why you couldn’t find all the branches in VS Code.