代码之家  ›  专栏  ›  技术社区  ›  Raz

如何将新项目连接到Github存储库?

  •  0
  • Raz  · 技术社区  · 6 年前

    我刚刚创建了一个新项目并在那里添加了一些文件。 然后我创建了一个新的Github存储库(public)。

    现在我要将本地Git项目推送到远程GitHub。

    所以我这样做:

    git init
    git add .
    git commit -m "First commit"
    

    然后:

    git remote add https://github.com/user/project.git
    git remote -v
    # origin    https://github.com/user/project (fetch)
    # origin    https://github.com/user/project (push)
    

    然后我试图推动我的新项目项目:

    git push
    # fatal: The current branch master has no upstream branch.
    # To push the current branch and set the remote as upstream, use
    # git push --set-upstream origin master
    

    所以我是这样做的:

    git push --set-upstream origin master
    And get back:
    # To https://github.com/user/project
    # ! [rejected]        master -> master (non-fast-forward)
    # error: failed to push some refs to 'https://github.com/user/project'
    # hint: Updates were rejected because the tip of your current branch is # behind
    # hint: its remote counterpart. Integrate the remote changes (e.g.
    # hint: 'git pull ...') before pushing again.
    # hint: See the 'Note about fast-forwards' in 'git push --help' for details.
    

    所以我一直遵循他们的指示:

    git pull
    And I get:
    There is no tracking information for the current branch.
    Please specify which branch you want to merge with.
    See git-pull(1) for details.
    
        git pull <remote> <branch>
    
    If you wish to set tracking information for this branch you can do so with:
    
        git branch --set-upstream-to=origin/<branch> master
    

    继续做他们写的:

    git pull origin master
    And get back:
    From https://github.com/user/project
     * branch            master     -> FETCH_HEAD
    fatal: refusing to merge unrelated histories
    

    我只是通过使用

    git clone https://github.com/user/project
    

    但我不认为这是正确的工作方式,是吗?

    希望能得到一些提示。 谢谢。

    2 回复  |  直到 6 年前
        1
  •  1
  •   Stéphane Laurent    6 年前

    就我个人而言,我只需按以下步骤进行。我不跑步 git 在我的计算机上创建项目:

    • 在Github上创建回购

    • 克隆它

    • 移动获得的 .git 文件夹(可选 README 文件和 .gitignore 文件)到工作文件夹

    那你就准备好了 add ,请 commit ,请 push .

        2
  •  1
  •   kthatoto    6 年前

    你应该运行这个命令,
    git remote add origin https://github.com/user/project.git

    git remote add https://github.com/user/project.git