BitBucket - 错误:未能推送一些参考

Mil*_*los 4 git bitbucket laravel

我有一些项目想上传到我的 bitbucket 私人资料中。我执行了以下步骤,但出现错误。

  1. 使用以下命令将我的项目转换为 git: git init

  2. 下一个:

git add
git commit -m "some message"
Run Code Online (Sandbox Code Playgroud)
  1. 我创建了一个 bitbucket 存储库,版本控制系统是 GIT。

  2. 然后我输入这个(当然用真实的帐户名和 reponame 和 repo 所有者):

git remote add origin https://<repo_owner>@bitbucket.org/<accountname>/<reponame>.git
Run Code Online (Sandbox Code Playgroud)
  1. 最后,
git push -u origin master
Run Code Online (Sandbox Code Playgroud)

我做了所有这些,我的终端给了我这个错误:

To https://bitbucket.org/milosdev_me/lfs.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://milosdev_me@bitbucket.org/milosdev_me/lfs.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Run Code Online (Sandbox Code Playgroud)

小智 25

尝试:

git push origin master --force
Run Code Online (Sandbox Code Playgroud)

这对我有用。

  • 这很好用。但为什么会出现这个错误呢? (2认同)

zla*_*tan 5

你的master分支有一些你没有的代码,locally为了防止冲突,它不允许你在本地拥有它们之前推送进一步的更改。要解决此问题,请将所有更改拉到您的local repository (您的项目)中:

git pull origin master --allow-unrelated-histories
Run Code Online (Sandbox Code Playgroud)

之后,您将拥有master分支上可用的所有代码。

注意:小心,从远程分支拉取代码可能会弄乱本地的所有更改。确保将这些更改保存在某处,或者在本地创建另一个分支,您将在其中拉取源master分支,这样就不会弄乱您的更改。


小智 1

您的远程存储库和本地存储库有差异,远程存储库中有一些新内容。因此,为了推送,您需要提前从远程拉取更改。尝试做:

git pull
git push -u origin master
Run Code Online (Sandbox Code Playgroud)