github cli 创建远程仓库并推送到github

该文详细介绍了如何在macOS系统中安装GitHubCLI,通过Homebrew执行`brewinstallgh`。接着,文章指导用户进行CLI登录,创建和上传SSHkey,设置认证token。然后,展示了如何使用gh命令创建远程仓库,将本地仓库推送到GitHub,包括设置仓库名称、描述、可见度以及添加远程分支。最后,文章列出了其他可用的gh命令选项。
摘要由CSDN通过智能技术生成

以下操作基于macOS,其他系统安装请参阅官方文档cli/cli: GitHub’s official command line tool

1. 安装github cli

brew install gh

2. 登录

以下操作步骤基本上就是上下方向键进行选择,然后回车。Token需要访问这里手动创建并粘贴。Token的权限应该至少包括repo, read:org, admin:public_key.

# 输入登录命令
gh auth login
# 选择登录网站GitHub.com
? What account do you want to log into?  -> GitHub.com
# 选择协议,我选SSH
? What is your preferred protocol for Git operations?  -> SSH
# 选择并上传上传SSH public key
? Upload your SSH public key to your GitHub account?  -> /Users/simonliu/.ssh/id_rsa.pub
# 设置key的title
? Title for your SSH key:  -> GitHub CLI
# 选择认证方式,我这里选token
? How would you like to authenticate GitHub CLI?  ->Paste an authentication token
Tip: you can generate a Personal Access Token here https://github.com/settings/tokens
The minimum required scopes are 'repo', 'read:org', 'admin:public_key'.
? Paste your authentication token: ****************************************
- gh config set -h github.com git_protocol ssh
✓ Configured git protocol
✓ Authentication complete.

3. 在本地仓库文件夹创建远程仓库并推送到服务器

基本上就是输入 gh repo create然后一路根据提示操作即可。

# 3.1 创建远程 repository
gh repo create
# 3.2 输入本地仓库路径,默认是当前路径 .
? Path to local repository -> .
# 3.3 选择行为:推送本地仓库至github
? What would you like to do? -> Push an existing local repository to GitHub
# 3.4 设置仓库名称,注意不要使用中文,否则中文字符会被替换为英文破折号
? Repository name -> epub_convert_tool
# 3.5 输入描述
? Description -> epub转换工具
# 3.5 选择可见度
? Visibility -> Private
✓ Created repository simonliu009/epub_convert_tool on GitHub
# 3.6 为本地仓库增加remote
? Add a remote? -> Yes
# 3.7 设置remote名称
? What should the new remote be called? -> origin
✓ Added remote git@github.com:simonliu009/epub_convert_tool.git
# 3.8 是否将当前分支的提交推送到origin,选择Yes
? Would you like to push commits from the current branch to "origin"?  ->Yes
Warning: Permanently added 'github.com,20.205.243.166' (ECDSA) to the list of known hosts.
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 4 threads
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 3.61 KiB | 3.61 MiB/s, done.
Total 5 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), done.
To github.com:simonliu009/epub_convert_tool.git
* [new branch]      HEAD -> main
Branch 'main' set up to track remote branch 'main' from 'origin'.
✓ Pushed commits to git@github.com:simonliu009/epub_convert_tool.git

4. 其他gh命令

gh repo --help
Work with GitHub repositories.

USAGE
  gh repo <command> [flags]

GENERAL COMMANDS
  create:      Create a new repository
  list:        List repositories owned by user or organization

TARGETED COMMANDS
  archive:     Archive a repository
  clone:       Clone a repository locally
  delete:      Delete a repository
  deploy-key:  Manage deploy keys in a repository
  edit:        Edit repository settings
  fork:        Create a fork of a repository
  rename:      Rename a repository
  set-default: Configure default repository for this directory
  sync:        Sync a repository
  unarchive:   Unarchive a repository
  view:        View a repository

INHERITED FLAGS
  --help   Show help for command

ARGUMENTS
  A repository can be supplied as an argument in any of the following formats:
  - "OWNER/REPO"
  - by URL, e.g. "https://github.com/OWNER/REPO"

EXAMPLES
  $ gh repo create
  $ gh repo clone cli/cli
  $ gh repo view --web

LEARN MORE
  Use 'gh <command> <subcommand> --help' for more information about a command.
  Read the manual at https://cli.github.com/manual
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值