git - 网站初始下载到github

标签 git github

我已经在我的服务器上安装了 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 to git@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 of git 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/

相关文章:

git - 可移植开发环境和 Git

带有中央存储库的 Git

git - 分支未出现在新远程 'gitlab'

git - 什么是 Git 快进?

java - 使用 Java 检查 Git 存储库是私有(private)的还是公共(public)的(例如 GitHub)

github - 如何将 github 私有(private)仓库添加到我的 Helm 环境中

github - 使用 github 有没有办法只看一个分支?

git push heroku master 权限被拒绝(公钥)。致命的 : The remote end hung up unexpectedly

ruby-on-rails - 访问 GitHub 私有(private)仓库时部署到 ec2 实例失败

github - 如何在 Atom 文本编辑器中克隆所有分支而不仅仅是掌握