65

I've been using Visual Studio code for a long time, since v0.9.1. I now have run into the need to use GitHub and an online Git repository.

I have the online Git repository set up and have been pushing changing to the online repository using GitHub. I have recently come to realize I can save myself a step with using Visual Studio Code to do both: to edit my code, then send it up to the online repository.

I am very new to the whole Git concept. Visual Studio Code had me install the "Git" plugin which installed Git Bash, Git CMD, and Git GUI.

This is the online repository URL I'm trying to get to: https://github.com/SpectrumGraphics/Spectrum-Graphic-Designs.git

Visual Studio Code GitPlugin Visual Studio had my install

0

5 Answers 5

86
  1. Open Visual Studio Code terminal (Ctrl + `)
  2. Write the Git clone command. For example,

    git clone https://github.com/angular/angular-phonecat.git
    
  3. Open the folder you have just cloned (menu FileOpen Folder)

    Enter image description here

4
  • 3
    In other words, Visual Studio Code allows you do this OOTB. Thanks this works and should be a native IDE answer for the OP.
    – klewis
    Jul 28, 2017 at 17:38
  • 1
    For newbe to get the URL in (as above) "Write git clone command. For example git clone github.com/angular/angular-phonecat.git" .. from the GitHub repository: Press [Clone or Download] then the copy icon. Sep 6, 2018 at 8:21
  • how do i switch to child branch in VS Code ? Feb 17, 2020 at 13:45
  • @DhavalPankhaniya - there is no child branch concept in git. it just have a particular commit path. you just witch from branch to branch using git checkout <brachname> command.
    – Shahdat
    Feb 18, 2020 at 20:09
23

Another option is to use the built-in Command Palette, which will walk you right through cloning a Git repository to a new directory.

From Using Version Control in VS Code:

You can clone a Git repository with the Git: Clone command in the Command Palette (Windows/Linux: Ctrl + Shift + P, Mac: Command + Shift + P). You will be asked for the URL of the remote repository and the parent directory under which to put the local repository.

At the bottom of Visual Studio Code you'll get status updates to the cloning. Once that's complete an information message will display near the top, allowing you to open the folder that was created.

Note that Visual Studio Code uses your machine's Git installation, and requires 2.0.0 or higher.

2
  • 1
    Do you know if Git Cmd git-scm.com/download/win (caution auto download, but not execute on link) is required for VS Code clone? I had previously used GItHub Desktop for a clone and it needed the Git Cmd to work. So it was in place when I did another clone with VS Code. Dec 5, 2017 at 16:01
  • 3
    Good question. Normally I just install Git, so I had to check. According to code.visualstudio.com/docs/editor/versioncontrol#_git-support "Note: VS Code will leverage your machine's Git installation, so you need to install Git first before you get these features. Make sure you install at least version 2.0.0." So yes. Although I'm surprised GitHub Desktop required a separate Git install; I thought it came with one. Dec 5, 2017 at 20:48
8
  1. Use git clone to clone your repository into a folder (say work). You should see a new subfolder, work/.git.
  2. Open folder work in Visual Studio Code - everything should work fine!

PS: Blow away the temporary folder.

5

Use the Git GUI in the Git plugin.

Clone your online repository with the URL which you have.

After cloning, make changes to the files. When you make changes, you can see the number changes. Commit those changes.

Fetch from the remote (to check if anything is updated while you are working).

If the fetch operation gives you an update about the changes in the remote repository, make a pull operation which will update your copy in Visual Studio Code. Otherwise, do not make a pull operation if there aren't any changes in the remote repository.

Push your changes to the upstream remote repository by making a push operation.

6
  • awesome thank you, quick question, its asking me for a source location and target directory?
    – Charles L.
    Oct 22, 2015 at 15:45
  • When you are trying to clone?
    – Vamsi Ravi
    Oct 22, 2015 at 18:19
  • I think it is the source repository not the source location, which is your url. The target directory or location is your local drive into which you want to clone the remote code.
    – Vamsi Ravi
    Oct 22, 2015 at 18:40
  • 3
    Which git GIT Plugin? There's dozens of them.
    – aagha
    Feb 18, 2018 at 6:20
  • You should probably mention which Git plugin you are referring to. Jan 22, 2020 at 7:22
1
  1. Open Vs Code
  2. Go to view
  3. Click on terminal to open a terminal in VS Code
  4. Copy the link for your existing repository from your GitHub page.
  5. Type “git clone” and paste the link in addition i.e “git clone https://github.com/...”
  6. This will open the repository in your Vs Code Editor.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.