gitgithubcodespaces

How to create GitHub Codespace from current git directory repository?


I want through the terminal to create a new codespace on Github, from the current git repository.

I can create codespace from gh with this params

$ gh codespace create
? Repository: [? for help, tab for suggestions]

and then enter repo name with username/repo-name format.


Solution

  • You can get the repo name with username/repo-name format from the git URL, and then create a codespace from them.

    1. get git repository URL
    git config --get remote.origin.url
    
    1. remove domain and .git from URL to have username/repo-name format
    $ git config --get remote.origin.url  | sed 's/https:\/\/github\.com\///' | sed 's/\.git$//'
    
    1. pipe name to gh command
    $ git config --get remote.origin.url  | sed 's/https:\/\/github\.com\///' | sed 's/\.git$//' | xargs gh codespace create -r