我昨天还能推,现在却推不动了。

当我使用git push origin master时,我得到一个错误:

$ git remote -v
origin  https://github.com/REDACTED.git (fetch)
origin  https://github.com/REDACTED.git (push)

$ git push origin master
Username for 'https://github.com': REDACTED
Password for 'https://REDACTED@github.com':
To https://github.com/REDACTED.git
! [rejected]         master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/REDACTED.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 rm --cached *
git add .
git commit -m"upload"
git push --set-upstream origin master

其他回答

这些步骤对我很有效:

切换到当前分支和拉最新的代码 重命名本地分支 Git分支-m [new-name] 将本地分支推到服务器 Git push origin [new-name] 从服务器中删除分支 Git push origin——delete [old-name]

我也遇到过同样的问题,并通过以下步骤解决了它。

git init Git添加。 git commit -m '添加提交信息' git远程添加origin https://User_name@bitbucket.org/User_name/sample.git (上面的URL, https://User_name@bitbucket.org/User_name/sample.git,指的是你的Bitbucket项目的URL) Git push -u origin master

Hint

检查你的GitHub账户是否连接到你的本地Git存储库:

git config --global user.email "you@example.com"
git config --global user.name "Your Name"

通过遵循文档,你只需要把它拉到你的Github项目中。

git init -b main

git add . && git commit -m "Commit Here"

git remote add origin  <REMOTE_URL>

git remote -v

git pull origin main

git push origin main

以下是我处理这类问题的一些解决方案:

fatal:无法访问<REMOTE_URL>:请求的URL返回错误:400

git remote set-url origin <REMOTE_URL>

致命的:拒绝合并不相关的历史

git pull origin main --allow-unrelated-histories

对我来说,我忘记在点击推送之前添加和提交。

So:

git add --all
git commit -m "First commit."

然后按一下,就可以了:)

我尝试了'git push origin main',然后收到了消息。然后我尝试单独使用“git push”,但它不起作用。

我检查了一下我是否承诺了(是的)。我试着“拉”,然后“推”,但没有。

在开始一些特技之前,我只是关闭并打开一个新的终端,然后再次“推”,它工作了:p