【问题标题】:Why I am not able to push my code to BitBucket?为什么我无法将我的代码推送到 BitBucket?
【发布时间】:2021-10-05 17:39:59
【问题描述】:

我正在开发一个flutter 应用程序并尝试将我的代码发送到bitbucket。我做了以下步骤。

  1. 转到bitbucket 并在该新存储库下创建一个新项目。
  2. 复制repo url,类似于https://abcd@bitbucket.org/abcd/my_project.git
  3. 使用终端导航到我的 Flutter 应用文件夹。
  4. 输入git init
  5. 输入git remote add origin https://abcd@bitbucket.org/abcd/my_project.git
  6. 输入git add *
  7. 输入git commit -m "first commit"
  8. 输入git pull origin master
  9. 输入git add *
  10. 输入git commit -m "second commit"(实际上这里没什么可提交的,我只是这样做了)
  11. 输入git push origin master

现在我收到以下错误

To https://bitbucket.org/abcd/my_project.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://bitbucket.org/abcd/my_project.git'
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 origin master

【问题讨论】:

  • 您是否尝试过通过https://abcd@bitbucket.org/abcd/my_project.git 简化克隆,然后通过git commit 提交和推送文件?
  • @AntonioPetricca:我不能。我正在尝试将现有项目推送到远程仓库,而不是相反。
  • 试试我的完整答案,告诉我它是否有效。
  • @AntonioPetricca:好的,等待答案。

标签: git flutter github visual-studio-code bitbucket


【解决方案1】:

你应该依靠一个不太复杂的过程来做同样的事情。

请尝试:

git clone https://abcd@bitbucket.org/abcd/my_project.git
cd my_project
cp -rv <MY_SOURCES_PATH>/* .
git add --all
git commit -m "A comment"
git push

让我知道它是否有效。

问候。

【讨论】:

    【解决方案2】:

    问题是有一个未同步的文件.gitignore。默认情况下不提交。所以我不得不

    git add .gitignore
    

    git commit -m "message"
    

    【讨论】:

      猜你喜欢
      • 2018-03-06
      • 1970-01-01
      • 1970-01-01
      • 2014-03-18
      • 2013-09-11
      • 2017-01-25
      • 2017-12-23
      • 2020-02-21
      • 1970-01-01
      相关资源
      最近更新 更多