我已经在我的服务器上安装了 Git,并且已经成功连接到 Github。 我现在想将我的网站(已经开发)下载到 Github 以开始版本跟踪。但是,我在执行此操作时遇到了问题。
我已经注册了 Github 并创建了一个带有自述文件的空白存储库。
我已经登录到我的服务器并创建了 id_rsa.pub 我已经使用 cat 复制了 id_rsa.pub 的内容,并将 key 放入我的 github 帐户。
我现在想将我的网站推送到 Github 上的存储库。
但是,我似乎无法让它工作。请问有人可以给我一个演练吗? 这是从服务器到 Github 的初始下载。
当我这样做
git push -u origin master
我回来了:
To
git@github.com:<github-username>/<github-repo-name>.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs togit@github.com:<github-username>/<github-repo-name>.git
To prevent you from losing history, non-fast-forward updates were rejected Merge the remote changes (e.g.git pull
) before pushing again. See the 'Note about fast-forwards' section ofgit push --help
for details.
当我这样做
git pull
我回来了:
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 master <remote>/<branch>
最佳答案
首先,您需要:
git pull origin master
从服务器引入更改。
然后,git push origin master
将起作用。
这是因为您使用自述文件创建了一个存储库,并在您的本地副本中执行了 git init
而不是 clone
。
创建自述文件会导致 github 创建一个存储库,但随后也会将自述文件推送到存储库 - 您的存储库的服务器版本现在有一个本地版本没有的提交。因此,在将文件推送到 github 之前,您需要使本地副本与 github 同步。
关于git - 网站初始下载到github,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10518393/