GitHub

GitHub

💡 原文约1600字/词,阅读约需6分钟。
📝

内容提要

Git是流行的版本控制工具,常用命令包括:`git remote remove origin`(删除远程仓库)、`git remote add origin`(添加远程仓库)、`git push`(推送更改)、`git pull`(拉取更改)、`git branch`(管理分支)、`git checkout`和`git switch`(切换分支)。GitHub CLI可快速创建远程仓库。

🎯

关键要点

  • Git是流行的版本控制工具。
  • git remote remove origin - 删除远程仓库。
  • git remote add origin (url) - 添加远程仓库。
  • git push - 将本地更改推送到远程仓库。
  • -u(或--set-upstream)- 设置跟踪远程分支。
  • git pull - 从远程仓库拉取最新更改并合并到本地分支。
  • git branch - 显示当前所在的分支。
  • git branch <branch_name> - 创建新分支。
  • git checkout <branch_name> - 切换到指定分支。
  • git switch <branch_name> - 新版本的切换分支命令。
  • git switch -c <branch_name> - 创建新分支并切换到该分支。
  • git checkout -b <branch_name> - 创建新分支并立即切换。
  • 使用GitHub CLI可以快速创建远程仓库。
  • gh repo create --public --source=. --remote=origin - 创建新的GitHub仓库。
  • --source=. - 指定当前目录作为新仓库的内容来源。
  • git init - 创建一个空的本地仓库。
  • 有效管理远程仓库对于团队协作和代码同步至关重要。

延伸问答

如何删除远程仓库?

使用命令 `git remote remove origin` 可以删除远程仓库。

如何将本地更改推送到远程仓库?

使用命令 `git push -u origin master` 可以将本地更改推送到远程仓库。

如何从远程仓库拉取最新更改?

使用命令 `git pull` 可以从远程仓库拉取最新更改并合并到本地分支。

如何创建新分支并切换到该分支?

可以使用命令 `git checkout -b <branch_name>` 或 `git switch -c <branch_name>` 来创建新分支并切换到该分支。

GitHub CLI 如何快速创建远程仓库?

使用命令 `gh repo create --public --source=. --remote=origin` 可以快速创建远程仓库。

--source= . 在创建仓库命令中有什么作用?

--source=. 指定当前目录作为新仓库的内容来源。

➡️

继续阅读