Reputation: 298
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.
Upvotes: 1
Views: 332
Reputation: 1330102
gh 2.21.0 (Dec. 2022) adds two new elements:
-R
for --repo
shorthand and deprecate -r
gh codespace create
: allow setting display name for the new codespace.So:
cd /path/to/current/local/repository
gh repo set-default
gh codespace create -R $(gh repo view --json owner,name --jq '"\(.name)/\(.owner.login)"') \
--display-name yourName
See "Github CLI add another remote and work with it" on the new necessity to define your current repository as the default one.
See gh
formatting on --json --jq
formatting options, which allows to extract owner/name
from the current repository:
gh repo view --json owner,name --jq '"\(.name)/\(.owner.login)"'
# on CMD Windows
gh repo view --json owner,name --jq "\"\(.name)/\(.owner.login)\""
Upvotes: 1
Reputation: 298
You can get the repo name with username/repo-name format from the git URL, and then create a codespace from them.
git config --get remote.origin.url
username/repo-name
format$ git config --get remote.origin.url | sed 's/https:\/\/github\.com\///' | sed 's/\.git$//'
$ git config --get remote.origin.url | sed 's/https:\/\/github\.com\///' | sed 's/\.git$//' | xargs gh codespace create -r
Upvotes: 1