[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git: Checkout to a tracked local branch instead when trying to checkout to a remote branch #61149

Merged
merged 8 commits into from
May 27, 2019

Conversation

laphets
Copy link
Contributor
@laphets laphets commented Oct 17, 2018

Fix #60904

Description

Problem raised when trying to checkout a remote branch, while there existing a local branch having the same name.

Solution

Basically, we can check whether the remote branch name matches with any local branch. However, I think it's confusing sometimes when the local branch is tracking to an upstream branch with another name. Therefore, I think it's better to judge by the tracking ship instead of simply branch name.
By using

git for-each-ref --format='%(refname:short) -> %(upstream:short)' refs/heads

we can get all the tracking relations from local branch to the upstream branch, just as what is shown in the capture below.
image

Therefore, I add a GetTracking method in extensions/git/src/git.ts to parse for the tracking relationship and return. And when a user is trying, for instance, checkout to origin/master, vscode will find the tracking relation from master to origin/master, and checkout to master instead.

121

@laphets laphets changed the title Git: Checkout to a tracking local branch instead of an upstream branch Git: Checkout to a tracking local branch instead of a remote branch Oct 17, 2018
@laphets laphets changed the title Git: Checkout to a tracking local branch instead of a remote branch Git: Checkout to a tracking local branch instead when try to checkout a remote branch Oct 17, 2018
@laphets laphets changed the title Git: Checkout to a tracking local branch instead when try to checkout a remote branch Git: Checkout to a tracking local branch when trying to checkout to a remote branch Oct 17, 2018
@laphets laphets changed the title Git: Checkout to a tracking local branch when trying to checkout to a remote branch Git: Checkout to a tracked local branch instead when trying to checkout to a remote branch Oct 17, 2018
Update extensions/git/src/api/git.d.ts

Fix another typo

Fix some typo
@laphets laphets force-pushed the fix-branch-checkout branch from 852c8be to d24031b Compare October 18, 2018 02:57
@laphets
Copy link
Contributor Author
laphets commented Oct 18, 2018

@joaomoreno Could you help me check this, thx..

@joaomoreno joaomoreno self-assigned this Oct 19, 2018
@joaomoreno joaomoreno added this to the Backlog milestone Oct 19, 2018
@joaomoreno joaomoreno added the git GIT issues label Oct 19, 2018
@Astrantia
Copy link

@joaomoreno this is vital

@joaomoreno
Copy link
Member

Thanks! 🎆

@joaomoreno joaomoreno merged commit a84421b into microsoft:master May 27, 2019
@github-actions github-actions bot locked and limited conversation to collaborators Mar 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
git GIT issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Git fails to checkout remote branch with the same name as a local branch
4 participants