Upgrading to Visual Studio 2019 16.8.X has a new git workflow. This also includes a fetch button.
I am learning how to use Git with Visual Studio. I recently did a pull request where the feature branch was deleted after the merge. The feature branch still shows up in my local and remote branches in Visual Studio. I know how to right click and delete the branch, this is a workaround as others on the team may complete a pull request on a branch that I have without me knowing it. If they delete the branch afterwards I would not know they did so.
How do you refresh Visual Studio branches with what is on Git?
I would expect a button, link, or right click feature that on click checks for differences, if any are found it asks, "This branch no longer exists, would you like to remove it from Visual Studio?".
I am using Visual Studio 2015 Enterprise (still seems to be a symptom of VS 2019 for versions lower than 16.8)
This could be another question, but it fits so well here. I just noticed that if I create a branch (say in one VM and look at the same repo with another), Visual Studio does not have a git fetch
option to update the branch list. The refresh button at the top does not seem to do anything. As soon as I run git fetch
in a bash, visual studio has the new branch. I would expect the refresh to take care of this.
Solution. You just need to run git fetch --prune command in your solution directory using GIT Bash or Command Prompt. After running this command, you will find that deleted remote branches are no longer showing up in remotes/origin section in Visual Studio.
For more information on Sync, see Use git fetch, pull, push and sync for version control in Visual Studio. Open the Team Explorer and open the Sync view. Then select the Pull link under Incoming Commits to pull remote changes and merge them into your local branch.
If the branch has been deleted on the server side, try in command line (since such a "button" doesn't seem to exist directly in Visual Studio):
git remote prune origin --dry-run
(remove the --dry-run
option to actually delete the local branches)
Delete the corresponding local branch as well git branch -d aBranch
.
Then restart your Visual Studio, and check it picks up the updated branch list. (comments mention you don't have to restart/refresh VS)
Note: I mentioned before in 2013 the configuration
git config remote.origin.prune true
That would automate that process, and seems to be supported by Visual Studio, as mentioned below by yaniv.
On VSCode, try also to activate the setting "Git: Prune on Fetch"
"git.pruneOnFetch": true
From : "Refresh git remote branches in Visual Studio"
You can configure git to do this automatically on fetch/pull running with this command:
git config remote.origin.prune true –global
Update:
Visual Studio 2017 version 15.7.3 and above you can do it using the UI :
In Team Explorer , click the Home then Setting:
Select Global settings
Change "Prune remote branches during fetch" to "True"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With