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

Adding an existing project to GitHub using the command line

Putting your existing work on GitHub Enterprise can let you share and collaborate in lots of great ways.

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

Tip: If you're most comfortable with a point-and-click user interface, try adding your project with GitHub Desktop. For more information, see "Adding a repository from your local computer to GitHub Desktop" in the GitHub Desktop Help.

警告:切勿 git add、“提交”或“推送”敏感信息到远程仓库。敏感信息可包括但不限于:

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

  1. Create a new repository on 您的 GitHub Enterprise Server 实例. To avoid errors, do not initialize the new repository with README, license, or gitignore files. You can add these files after your project has been pushed to GitHub Enterprise.

    Create New Repository drop-down

  2. Open TerminalTerminalGit Bashthe terminal.

  3. Change the current working directory to your local project.

  4. Initialize the local directory as a Git repository.

    $ git init
  5. Add the files in your new local repository. This stages them for the first commit.

    $ git add .
    # Adds the files in the local repository and stages them for commit. 要取消暂存文件,请使用 'git reset HEAD YOUR-FILE'。
  6. Commit the files that you've staged in your local repository.

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

    Copy remote repository URL field

  8. In Terminal, add the URL for the remote repository where your local repository will be pushed.

    $ git remote add origin remote repository URL# Sets the new remote
    $ git remote -v
    # Verifies the new remote URL
  9. Push the changes in your local repository to 您的 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. Create a new repository on 您的 GitHub Enterprise Server 实例. To avoid errors, do not initialize the new repository with README, license, or gitignore files. You can add these files after your project has been pushed to GitHub Enterprise.

    Create New Repository drop-down

  2. Open TerminalTerminalGit Bashthe terminal.

  3. Change the current working directory to your local project.

  4. Initialize the local directory as a Git repository.

    $ git init
  5. Add the files in your new local repository. This stages them for the first commit.

    $ git add .
    # Adds the files in the local repository and stages them for commit. 要取消暂存文件,请使用 'git reset HEAD YOUR-FILE'。
  6. Commit the files that you've staged in your local repository.

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

    Copy remote repository URL field

  8. In the Command prompt, add the URL for the remote repository where your local repository will be pushed.

    $ git remote add origin remote repository URL# Sets the new remote
    $ git remote -v
    # Verifies the new remote URL
  9. Push the changes in your local repository to 您的 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. Create a new repository on 您的 GitHub Enterprise Server 实例. To avoid errors, do not initialize the new repository with README, license, or gitignore files. You can add these files after your project has been pushed to GitHub Enterprise.

    Create New Repository drop-down

  2. Open TerminalTerminalGit Bashthe terminal.

  3. Change the current working directory to your local project.

  4. Initialize the local directory as a Git repository.

    $ git init
  5. Add the files in your new local repository. This stages them for the first commit.

    $ git add .
    # Adds the files in the local repository and stages them for commit. 要取消暂存文件,请使用 'git reset HEAD YOUR-FILE'。
  6. Commit the files that you've staged in your local repository.

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

    Copy remote repository URL field

  8. In Terminal, add the URL for the remote repository where your local repository will be pushed.

    $ git remote add origin remote repository URL# Sets the new remote
    $ git remote -v
    # Verifies the new remote URL
  9. Push the changes in your local repository to 您的 GitHub Enterprise Server 实例.

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

Further reading

问问别人

找不到要找的内容?

联系我们