我如何创建一个新的存储库并将其上传到GitHub

发布于 2025-02-12 10:58:26 字数 55 浏览 1 评论 0原文

我不知道要创建一个新的存储库。

我需要完成一个项目,但我对存储库创建步骤一无所知。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

绮筵 2025-02-19 10:58:26

如果您的计算机上有一个预先存在的代码库(我认为是这种情况),并且您需要将此代码库“上传”到GitHub,则您需要执行一些操作:

  1. 在上github。如果您不熟悉命令行,建议您在Web UI上进行。您应该按照 @ben答案中的链接:在上github

  2. 初始化机器上的本地存储库。为此,您应该将终端和cd启动到代码库的文件夹中。

      CD/PATH/TO/您的/代码
    git init
     
  3. 将您的本地存储库与GitHub上的远程存储库联系起来。
    转到您新创建的回购,复制链接,如下图所示:

    “

    确保您要复制https url。 ssh类型URL需要更多的配置,并且当您更愿意使用gitssh tooling时,可以执行此操作。

    然后运行以下命令:

      git Remote添加Origin<您的回购URL>
     

    您可以在此处阅读有关Git Repo,Remote Repo和local Repo的更多信息

  4. 提交并推动您的代码。

      git commit -a -m“初始提交”
    git推出原点
    #您将需要输入您的用户名和密码
     

    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:

  1. 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

  2. Initialize a local repo on your machine. To do this, you should fire up a terminal and cd into the folder of your codebase.

    cd /path/to/your/code
    git init
    
  3. 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:

    Repo url

    Ensure you are copying the https URL. The ssh type URL requires a little bit more configurations, and you can do this when you are more comfortable with working with git and ssh tooling.

    Then run the following command:

    git remote add origin <your repo url>
    

    You can read more about git repo, remote repo and local repo here

  4. Commit and push your code.

    git commit -a -m "initial commit"
    git push origin main
    # you will be required to enter your username and password
    

    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

人间☆小暴躁 2025-02-19 10:58:26

如果您要在github上创建本地的新存储库,则可以使用 github cli gh

一次安装,用 gh auth登录 ,然后使用 gh repo创建

如果您还没有存储库:

# create a new remote repository and clone it locally
gh repo create my-project --public --clone

如果您已经在本地拥有一个存储库:

# create a remote repository from the current directory
cd /path/to/my/local/repository
gh repo create my-project --private --source=. --remote=upstream
git push -u main

使用- 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 with gh repo create

If you don't have a repository yet:

# create a new remote repository and clone it locally
gh repo create my-project --public --clone

If you already have a repository locally:

# create a remote repository from the current directory
cd /path/to/my/local/repository
gh repo create my-project --private --source=. --remote=upstream
git push -u main

Use --public or --private depending on the visibility you want to associate to the new GitHub repository.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文