我们经常发布文档更新,此页面的翻译可能仍在进行中。有关最新信息,请访问英文文档。如果此页面上的翻译有问题,请告诉我们

此版本的 GitHub Enterprise 将停止服务 此版本的 GitHub Enterprise 已停止服务 2020-01-22. 即使针对重大安全问题,也不会发布补丁。 要获得更好的性能、改进的安全性和新功能,请升级到 GitHub Enterprise 的最新版本。 如需升级方面的帮助,请联系 GitHub Enterprise 支持

使用命令行添加现有项目到 GitHub

将您的现有工作放到 GitHub Enterprise 上可通过许多很好的方式共享和协作。

如果要从 CodePlex 迁移项目,请阅读迁移指南以了解更多信息。

提示:如果您最喜欢点按式用户界面,请尝试使用 GitHub Desktop 添加项目。 更多信息请参阅 GitHub Desktop 帮助中的“从本地计算机添加仓库到 GitHub Desktop”。

警告:永远不要 git 添加提交推送敏感信息到远程仓库。 敏感信息包括但不限于:

更多信息请参阅“从仓库中删除敏感数据”。

  1. 在 您的 GitHub Enterprise Server 实例 上创建新仓库 为避免错误,请勿使用自述文件、许可或 gitignore 文件初始化新仓库。 您可以在项目推送到 GitHub Enterprise 之后添加这些文件。

    Create New Repository drop-down

  2. 打开 Terminal(终端)Terminal(终端)Git Bash

  3. 将当前工作目录更改为您的本地仓库。

  4. 将本地目录初始化为 Git 仓库。

    $ git init
  5. 在新的本地仓库中添加文件。 这会暂存它们用于第一次提交。

    $ git add .
    # Adds the files in the local repository and stages them for commit. 要取消暂存文件,请使用 'git reset HEAD YOUR-FILE'。
    
  6. 提交暂存在本地仓库中的文件。

    $ git commit -m "First commit"
    # Commits the tracked changes and prepares them to be pushed to a remote repository. 要删除此提交并修改文件,请使用 'git reset --soft HEAD~1' 并再次提交和添加文件。
    
  7. At the top of your GitHub Enterprise repository's Quick Setup page, click to copy the remote repository URL.

    创建远程仓库 URL 字段

  8. 在终端上,添加远程仓库的 URL(将在该 URL 推送本地仓库)。

    $ git remote add origin remote repository URL
    # Sets the new remote
    $ git remote -v
    # Verifies the new remote URL
  9. 推送更改(本地仓库中)到 您的 GitHub Enterprise Server 实例。

    $ git push -u origin master
    # Pushes the changes in your local repository up to the remote repository you specified as the origin
  1. 在 您的 GitHub Enterprise Server 实例 上创建新仓库 为避免错误,请勿使用自述文件、许可或 gitignore 文件初始化新仓库。 您可以在项目推送到 GitHub Enterprise 之后添加这些文件。

    Create New Repository drop-down

  2. 打开 Terminal(终端)Terminal(终端)Git Bash

  3. 将当前工作目录更改为您的本地仓库。

  4. 将本地目录初始化为 Git 仓库。

    $ git init
  5. 在新的本地仓库中添加文件。 这会暂存它们用于第一次提交。

    $ git add .
    # Adds the files in the local repository and stages them for commit. 要取消暂存文件,请使用 'git reset HEAD YOUR-FILE'。
    
  6. 提交暂存在本地仓库中的文件。

    $ git commit -m "First commit"
    # Commits the tracked changes and prepares them to be pushed to a remote repository. 要删除此提交并修改文件,请使用 'git reset --soft HEAD~1' 并再次提交和添加文件。
    
  7. At the top of your GitHub Enterprise repository's Quick Setup page, click to copy the remote repository URL.

    创建远程仓库 URL 字段

  8. 在命令提示中,添加远程仓库的 URL(将在该 URL 推送本地仓库)。

    $ git remote add origin remote repository URL
    # Sets the new remote
    $ git remote -v
    # Verifies the new remote URL
  9. 推送更改(本地仓库中)到 您的 GitHub Enterprise Server 实例。

    $ git push origin master
    # Pushes the changes in your local repository up to the remote repository you specified as the origin
  1. 在 您的 GitHub Enterprise Server 实例 上创建新仓库 为避免错误,请勿使用自述文件、许可或 gitignore 文件初始化新仓库。 您可以在项目推送到 GitHub Enterprise 之后添加这些文件。

    Create New Repository drop-down

  2. 打开 Terminal(终端)Terminal(终端)Git Bash

  3. 将当前工作目录更改为您的本地仓库。

  4. 将本地目录初始化为 Git 仓库。

    $ git init
  5. 在新的本地仓库中添加文件。 这会暂存它们用于第一次提交。

    $ git add .
    # Adds the files in the local repository and stages them for commit. 要取消暂存文件,请使用 'git reset HEAD YOUR-FILE'。
    
  6. 提交暂存在本地仓库中的文件。

    $ git commit -m "First commit"
    # Commits the tracked changes and prepares them to be pushed to a remote repository. 要删除此提交并修改文件,请使用 'git reset --soft HEAD~1' 并再次提交和添加文件。
    
  7. At the top of your GitHub Enterprise repository's Quick Setup page, click to copy the remote repository URL.

    创建远程仓库 URL 字段

  8. 在终端上,添加远程仓库的 URL(将在该 URL 推送本地仓库)。

    $ git remote add origin remote repository URL
    # Sets the new remote
    $ git remote -v
    # Verifies the new remote URL
  9. 推送更改(本地仓库中)到 您的 GitHub Enterprise Server 实例。

    $ git push origin master
    # Pushes the changes in your local repository up to the remote repository you specified as the origin

延伸阅读

问问别人

找不到要找的内容?

联系我们