How to clone a specific branch from new git Visual Studio 2019 (not from command)?

Viewed 13158

How to clone a specific branch from git Visual Studio 2019? I know how to do it in command but not sure how to di it using new git in Visual Studio 2019.

enter image description here

All I can do is to clone the master first and choose the specific branch from there.

2 Answers

While using Git, its advisable to use a CMD or PowerShell instance. Can you try:

git clone -b branch_name --single-branch 'repo_url'

branch_name is the name of your branch, and repo_url is the link of your remote repository (repository location).

If you want to get it done through the UI:

  1. You first need to go to Github
  2. From the branches dropdown click on the branch you need. You can view the dropdown here: enter image description here
  3. Then copy the Github URL (Copy from the address bar) and paste it in VS studio. That's it. enter image description here

If you click on different branches, the URLs will be different. For example now I selected constraints-2-0 and as you can see the URL at the top has changed. enter image description here

There seems to be only one route to get a branch via VS. It cannot be done directly but there is a simple path.

  1. Get the address of the main branch from the repo. Forget about branches at this point.

Get master address via clone option.

  1. Tell VS that you want to clone an existing repo.

Clone via VS

  1. Give VS the git repo address - it's in the paste buffer so just paste it into the repo location field. Set repo destination. Start clone operation.

Set VS repo info

  1. Observe VS complete operation. (If credentials are already correct.)

VS clone of master is successful.

  1. Switch to desired branch - in this example it's dev.

Switch to desired repo.

That's it. Hope that helps.

Related