简体   繁体   中英

How to create a github repository from the cli with git using only a token?

With github tokens, the easiest way I've found to work with a new repository is.

1. Create the new repo on the github site.
2. git clone https://[user]:ghp_asdcsdcasdcasdcasdcasdcasdc@github.com/[user]/repo-name.git   # Using token to authenticate
3. cd into that new folder and then put files in here and then add / commit / push
git add .  ;  git commit -m "test"  ;  git status  ;   git push -u origin master

This works, but cannot do the process purely from the cli, requiring the step on the site.

However, the "official" way (presented on the github site) is:

echo "# test-xxx" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/[user]/repo-name.git 
git push -u origin master

Obviously, password authentication is no longer available, so this automatically fails. So I updated the remote add origin to be git remove add origin https://[user]:ghp_asdcsdcasdcasdcasdcasdcasdc@github.com/[user]/repo-name.git

But this completely fails with the error:

remote: Repository not found.
fatal: repository 'https://github.com/[user]/repo-name.git/' not found

So the official way is broken (because it assumes that password authentication is going to work, but password authentication was removed in August 2021).

From cli, how do I create a repository under my account (using a token, not a password) and then start pushing changes to that repository?

This works, but cannot do the process purely from the cli, requiring the step on the site.

You don't have to do any step on the site, if you have installed locally the GitHub CLI gh

You can then:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM