Visual Studio Code - Connect to a remote Git repository and PUSH local files to a new remote repository

I assume you started to work in a directory and didn't use Git there. The following should work with Git Bash:

cd "path to your repository"
git init
git add . # If you want to commit everything. Otherwise use .gitconfig files
git commit -m "initial commit" # If you change anything, you can add and commit again...

To add a remote, just do

git remote add origin https://...
git remote show origin # If everything is ok, you will see your remote
git push -u origin master # Assuming you are on the master branch.

The -u sets an upstream reference and Git knows from where to fetch/pull and where to push in the future.


It is now possible to set the origin from Visual Studio Code without command line typing:

git remote add origin https://github.com/USR/REPO.git

From within Visual Studio Code you may Ctrl + SHIFT + P if you are on Windows and type remote.

From there select Git: Add Remote and you will have two steps:

  • Set origin for the remote name:
  • Add origin URL: https://github.com/USR/REPO.git

From comments:

VSCode does not support the "add remote" action in its UI (April 2018)

Actually, it does since Visual Studio Code 1.46 (May 2020):

Add remote from GitHub

You can now easily add a GitHub repository as a remote to your local repositories using the Git: Add Remote... command.

https://media.githubusercontent.com/media/microsoft/vscode-docs/vnext/release-notes/images/1_46/git-add-remote.gif