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

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

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

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

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

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

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

  1. 在 您的 GitHub Enterprise Server 实例 上创建新仓库 为避免错误,请勿使用自述文件、许可或 gitignore 文件初始化新仓库。 您可以在项目推送到 GitHub Enterprise Server 之后添加这些文件。 创建新仓库下拉列表
  2. 打开 Terminal(终端)Terminal(终端)Git Bash
  3. 将当前工作目录更改为您的本地仓库。
  4. 将本地目录初始化为 Git 仓库。
    $ git init -b main
  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. 在 GitHub Enterprise Server 仓库的 Quick Setup(快速设置)页面顶部,单击 复制远程仓库 URL。 创建远程仓库 URL 字段
  8. 在终端上,添加远程仓库的 URL(将在该 URL 推送本地仓库)。
    $ git remote add origin  <REMOTE_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 Server 之后添加这些文件。 创建新仓库下拉列表
  2. 打开 Terminal(终端)Terminal(终端)Git Bash
  3. 将当前工作目录更改为您的本地仓库。
  4. 将本地目录初始化为 Git 仓库。
    $ git init -b main
  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. 在 GitHub Enterprise Server 仓库的 Quick Setup(快速设置)页面顶部,单击 复制远程仓库 URL。 创建远程仓库 URL 字段
  8. 在命令提示中,添加远程仓库的 URL(将在该 URL 推送本地仓库)。
    $ git remote add origin  <REMOTE_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 Server 之后添加这些文件。 创建新仓库下拉列表
  2. 打开 Terminal(终端)Terminal(终端)Git Bash
  3. 将当前工作目录更改为您的本地仓库。
  4. 将本地目录初始化为 Git 仓库。
    $ git init -b main
  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. 在 GitHub Enterprise Server 仓库的 Quick Setup(快速设置)页面顶部,单击 复制远程仓库 URL。 创建远程仓库 URL 字段
  8. 在终端上,添加远程仓库的 URL(将在该 URL 推送本地仓库)。
    $ git remote add origin  <REMOTE_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

延伸阅读