Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将新项目连接到GitHub存储库?_Git_Github - Fatal编程技术网

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

如何将新项目连接到GitHub存储库?,git,github,Git,Github,我刚刚创建了一个新项目,并在那里添加了一些文件。 然后我创建了一个新的GitHub存储库(public) 现在,我想将本地Git项目推送到远程GitHub 所以我这样做: git init git add . git commit -m "First commit" 然后: 然后我尝试推送我的新项目项: git push # fatal: The current branch master has no upstream branch. # To push the current branch

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

现在,我想将本地Git项目推送到远程GitHub

所以我这样做:

git init
git add .
git commit -m "First commit"
然后:

然后我尝试推送我的新项目项:

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 clone https://github.com/user/project
但我不认为这是正确的工作方式,是吗

希望得到一些提示。
谢谢

您应该运行此命令,
git远程添加源https://github.com/user/project.git



git远程添加https://github.com/user/project.git

您应该运行此命令,
git远程添加源https://github.com/user/project.git



git远程添加https://github.com/user/project.git

就我个人而言,我只需执行以下操作。我不会在我的计算机上运行
git
来创建项目:

  • 在Github上创建回购协议

  • 克隆它

  • 将获得的
    .git
    文件夹(以及可选的
    自述文件
    文件和
    .gitignore
    文件)移动到工作文件夹


然后,您就可以进行
添加
提交
推送
,我个人只需执行以下操作。我不会在我的计算机上运行
git
来创建项目:

  • 在Github上创建回购协议

  • 克隆它

  • 将获得的
    .git
    文件夹(以及可选的
    自述文件
    文件和
    .gitignore
    文件)移动到工作文件夹


然后,您就可以开始执行不起作用的
添加
提交
推送

,并给出我上面提到的相同错误。然后尝试此操作,
git merge--允许不相关的历史源代码/主代码
。我认为您在创建GitHub存储库时创建了类似于
README.md
.gitignore
的文件。但是你在试着推而不拉他们。请原谅我的英语不好。这不起作用-给出了我上面提到的相同错误。然后尝试这个,
git merge--allow unrelated history origin/master
。我认为您在创建GitHub存储库时创建了类似于
README.md
.gitignore
的文件。但是你在试着推而不拉他们。请原谅我英语不好。
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