Search code examples
githubcodespacesgithub-codespaces

Use GitHub CodeSpace with multiple repositories


Is there any way to use a single CodeSpace with multiple repositories?

For example, I'd like to be able to create a CodeSpace for C++, and another for C#. Then use them to open whatever repository I want.

After reading all the GitHub docs it seems as though I have to create a new CodeSpace for every repo I work on. But that means reinstalling all my VsCode extensions and resynching my configuration every time I work on a new repo, or even just a repo I haven't worked on for a while as the CodeSpaces are automatically deleted after 30 days.

If I can't use the same CodeSpace to open different repos it seems like a massive impediment. Is there a mitigating workflow for this that I'm missing?


Solution

  • While GitHub Codespaces do have to be linked to a repository, it's of course possible to use multiple repositories in the same codespaces simply by cloning them into /workspaces (or wherever you have them configured). I do this all the time and it's not a problem. If you want to use the same token, GitHub has ways to configure a Codespace to access multiple repositories.

    It is, however, intended that Codespaces be mostly throwaway and replaceable. If you haven't already, I'd recommend setting up a script or similar tooling (I personally use an Ansible playbook along with a bound SSH port) to set up the tooling the way you like it. Then, the process of setting up the environment takes at most a few minutes and setting up a new environment is much less burdensome. Setting up the tooling does take some time, but the automation is well worth it.

    If you really want to create one per language instead of one per repository, you could create a repository that's just the devcontainer images (one for C++, one for C#, etc.) and then simply choose the right one when creating. You could also set up a different repository for each language and then grant permission to all of your projects in that language as outlined in the link above.