Working with VS Code Dev Containers and Git

One of the challenges developers face is to manage requirements of different projects while keeping their local environment functional. VS Code Dev Containers is a perfect solution to this challenge moreover, using VS Code Dev Containers, a developer can work with many different versions of libraries for different projects. While the local environment remains protected against configurations bummers and security threats that come with experimenting with untrusted code. In this blog we will see how to rightly setup VS Code Dev Containers to manage your code properly with git.

You are at the right place if you encountered: Please make sure you have the correct access rights and the repository exists. If you see this error while trying to push from visual studio code remote container. This article explains how to add existing code in a container to a remote repository.

Setting-up repos for existing code / experiments that started in vs dev containers

  1. Create a new repo on your hosting service, in this example, we will use Gitlab but instructions would remain the same for any other service.
  2. Don’t include a as shown in the image
  1. In the VS Code Dev container, open a terminal and set git globals
git config --global "Your Name"
git config --global "[email protected]"
  1. Assuming, you are in the project directory in dev container, initialize git repo
git init --initial-branch=main
git remote add origin

Notice, the highlighted text where we are using https address of the repo and not using ssh version. This is important to allow VS Code credentials helper to work and you not having to copy ssh keys to VS Code dev containers.

The https address can be found under Clone button on the page you should see after creating your repo on Gitlab as shown in this image

Gitlab Project Creation Page 2 : VS Code Dev Containers and Git
Gitlab Project Creation Page 2 : VS Code Dev Containers and Git
  1. Now, commit and push the code
git add .
git commit -m "Initial commit"
git push --set-upstream origin main

Once, you have the repo setup this way, you are all set to code from VS Code dev containers, happy coding!


Don’t hesitate, we are just a message away!

Leave a Reply

Your email address will not be published. Required fields are marked *

Signup for our newsletter