How to push to remote Git repo from VS Code Docker devcontainer on Windows with WSL2

I've been recently experimenting with migrating my local Laragon dev environment to Docker with Laravel Sail.

One of the problems I ran into, was pushing to my remote repo via SSH. I like to make a push directly from VS Code by selecting "push" option from the "source control" context menu. I'm talking about this option:

When I clicked on it, I was getting an error message: You don't have permissions to push to "example-org/example-repo" on GitHub. Would you like to create a fork and push to it instead?, like in the screenshot below:

The solution turned out to be pretty simple. I figured it out mostly based on reading the official VS Code Devcontainer documentation.

What you need to do is to add your private ssh key to ssh agent inside WSL2. Assuming the private key you're using to authenticate yourself with your remote git repo is in the `/home/your_user/.ssh` directory (the default), you need to run the following command in WSL2 terminal:

`ssh-add /home/your_user/.ssh/id_rsa`

You can then run a command ssh-add -l to confirm that the key was added successfully. If you see a message like:

`2048 SHA256:m7BP0oxxxxVXmAhNzmNphZiEmK4gWvLexxxxdlG9LAA /home/your_user/.ssh/id_rsa (RSA)`

it means that everything went fine.

With that, you're good to go. You will now be able to push to remote repo. No need to restart the devcontainer.