我如何创建一个新的存储库并将其上传到GitHub
我不知道要创建一个新的存储库。
我需要完成一个项目,但我对存储库创建步骤一无所知。
I don't know like to create a new repository.
I need to finish a project but I don't understand anything about the repository creation step.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的计算机上有一个预先存在的代码库(我认为是这种情况),并且您需要将此代码库“上传”到GitHub,则您需要执行一些操作:
在上github。如果您不熟悉命令行,建议您在Web UI上进行。您应该按照 @ben答案中的链接:在上github
初始化机器上的本地存储库。为此,您应该将终端和
cd
启动到代码库的文件夹中。将您的本地存储库与GitHub上的远程存储库联系起来。
转到您新创建的回购,复制链接,如下图所示:
确保您要复制
https
url。ssh
类型URL需要更多的配置,并且当您更愿意使用git
和ssh
tooling时,可以执行此操作。然后运行以下命令:
您可以在此处阅读有关Git Repo,Remote Repo和local Repo的更多信息
提交并推动您的代码。
github要求如果您在命令行中推动代码,则需要使用个人访问令牌。您可以参考此链接为自己创建PAT。
下一步您应该更多地了解
git
工具。我建议阅读 atlassian的git tutorial ,或=“ https://git-scm.com/book/en/v2” rel =“ nofollow noreferrer”> git书If you have a pre-existing codebase on your machine (which I assume is the case), and you need to "upload" this codebase to GitHub, then you would need to perform a few actions:
Create a new repo on GitHub. If you are not familiar with the command line, I suggest doing it on the Web UI. You should follow the link in @Ben's answer: Create a repo on GitHub
Initialize a local repo on your machine. To do this, you should fire up a terminal and
cd
into the folder of your codebase.Link up your local repo with the remote repo on GitHub.
Go to your newly created repo, copy the link as shown in the picture below:
Ensure you are copying the
https
URL. Thessh
type URL requires a little bit more configurations, and you can do this when you are more comfortable with working withgit
andssh
tooling.Then run the following command:
You can read more about git repo, remote repo and local repo here
Commit and push your code.
GitHub requires you to use a Personal Access Token if you are pushing your code in the command line. You can refer to this link to create a PAT for yourself.
The next step for you should be learning more about the
git
tooling. I would recommend reading Atlassian's git tutorial, or the Git book如果您要在github上创建本地和的新存储库,则可以使用 github cli
gh
。一次安装,用
gh auth登录
,然后使用gh repo创建
如果您还没有存储库:
如果您已经在本地拥有一个存储库:
使用
- public
或- 私有
取决于要与新GitHub存储库相关联的可见性。If you new repository is one you want to create locally and on Github, you can do so easily with the GitHub CLI
gh
.Once installed, authenticate yourself with
gh auth login
, then create your new repository withgh repo create
If you don't have a repository yet:
If you already have a repository locally:
Use
--public
or--private
depending on the visibility you want to associate to the new GitHub repository.