Git 强制更新一个分支

Git push force to update a branch

我有一个项目目录(没有 git 文件夹),我在其中工作并试图强制更新现有的远程分支。

我走过的步数 -

1. git init
2. git add .
3. git commit "Fresh update after changing db"
4. git remote add origin <repo_url>
5. git push origin staging

我得到以下错误 -

error: src refspec staging does not match any.
error: failed to push some refs to '<repo_url>'

当我执行 git branch -a 时,它不会只显示所有分支 master

非常感谢任何帮助。

添加远程后拉取:

1. git init
2. git add .
3. git commit "Fresh update after changing db"
4. git remote add origin <repo_url>
5. git checkout -b staging
6. git fetch
7. git push -f origin staging

Avoid using force push if possible. Let me know exact scenario for better solution.

您在 master 分支上并试图推送到远程 staging 分支。在提交和推送更改之前,您应该 git checkout -b staging 在本地:

git init
git add .
git checkout -b staging
git commit "Fresh update after changing db"
git remote add origin <repo_url>
git push origin staging