简体   繁体   中英

How do I refresh branches (local/remote) in Visual Studio when using Git?

Update

Upgrading to Visual Studio 2019 16.8.X has a new git workflow. This also includes a fetch button.

在此处输入图片说明

Summary

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.

Question

How do you refresh Visual Studio branches with what is on Git?

What I expect

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?".

Tech Specs

I am using Visual Studio 2015 Enterprise (still seems to be a symptom of VS 2019 for versions lower than 16.8)

Additional Example

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.

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 .

Thenrestart 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 .

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 :

  1. In Team Explorer , click the Home then Setting: 在此处输入图片说明

  2. Select Global settings

  3. Change "Prune remote branches during fetch" to "True"

According to this blog post , you can set a git property via

git config remote.origin.prune true

that will remove deleted branches from your list when you perform a fetch.

For those looking for how to configuring pruning in VS2019 it has moved under the 'Git' menu.

在此处输入图片说明

VS 2017 appears to have support configurable in Team Explorer:

Team Explorer Home Settings Git > Global Settings Prune Remote Branches During Fetch: Unset, True, or False

您应该先取消发布分支,然后其他人会注意到该分支未发布(通过尝试拉动分支他们会得到错误),删除本地分支实际上是一个单独的过程本身,必须完成才能摆脱反正分支。

I couldn't do it in the UI. I had to go into Terminal and type: git remote update (to update the list of branches, so that I could use the git checkout in the UI)

My folder was already open, and I had already added the remote via. the UI.

You could also use --prune at the end, which according to this deletes stale references. Using origin however just gave me an error saying, fatal: No such remote or remote group: origin .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM