Skip to main content
  1. Learn center
  2. Software Development
  3. Guides
  4. Git tutorial
  5. 如何使用 Git
  6. 如何在 Command Line 中使用 Git
  7. 推送到远程存储库
GuidesSoftware DevelopmentBacklog
Git

Project and code management together.

推送到远程存储库

让我们推送到您在本教程的开头时创建的本地存储库。

使用 git remote 命令tutorial存储库的 URL 来注册一个别名为origin的远程存储库。

The remote repository‘s URL is registered under the name origin
$ git remote add origin https://[your_space_id].backlog.com/git/[your_project_key]/tutorial.git

如果您在控制台上,如果您在推送/拉取时省略了远程名称,在默认情况下将会使用“origin”远程存储库。这是因为惯例通常使用“origin”作为远程名称。

接下来,使用 git push 命令将提交推送到远程存储库origin

指定要推送到的分支名称。(我们将在下个章节中更深入地讨论分支。)如果在执行命令时指定“-u”选项,则下次推送到远程存储库时可以省略分支名称。但是,当您推送到一个空的远程时,您必须指定远程存储库和分支名称。

如果系统要求您提供用户名和密码时,请输入您的 Backlog 用户凭据。

$ git push -u origin main
  Username:
  Password:
  Counting objects: 3, done.
  Writing objects: 100% (3/3), 245 bytes, done.
  Total 3 (delta 0), reused 0 (delta 0)
  To https://example.backlog.com/git/BLGGIT/tutorial.git
    * [new branch]      main -> main

打开 Backlog 上的 Git 页面,您会发现在“Recent Updates”下面,列出了一个与您推送到远程存储库相对应的最新更新。

The push item is added to the recent updates

进入 Git 页面后,单击进入教程存储库,并导航到 Files 选项卡。推送的文件也会出现在该选项卡中。

The file from the pushed repository is added

接下来,我们将克隆这个远程存储库。

Subscribe to our newsletter

Learn with Nulab to bring your best ideas to life