F:\databuilder\preferencedatabuilder>git push --force fatal: The current branch main has…
- User
F:\databuilder\preference_databuilder>git push --force fatal: The current branch main has no upstream branch. To push the current branch and set the remote as upstream, use
codegit push --set-upstream origin mainTo have this happen automatically for branches without a tracking upstream, see 'push.autoSetupRemote' in 'git help config'.
F:\databuilder\preference_databuilder>git push --set-upstream origin main To https://github.com/zjrwtx/preference_databuilder.git ! [rejected] main -> main (non-fast-forward) error: failed to push some refs to 'https://github.com/zjrwtx/preference_databuilder.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. If you want to integrate the remote changes, hint: use 'git pull' before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
F:\databuilder\preference_databuilder>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.
codegit pull <remote> <branch>If you wish to set tracking information for this branch you can do so with:
codegit branch --set-upstream-to=origin/<branch> main - Assistant
- User
用中文解释
- Assistant
当你使用Git进行版本控制时,遇到的命令序列和消息提示反映了一些常见的问题,特别是与分支跟踪和更新本地仓库副本有关的问题。让我们逐步了解发生了什么以及如何解决这些问题。
-
尝试强制推送而未设置上游分支: 起初,你尝试强制推送(
git push --force)更改到主分支,但因为你的本地分支没有设置上游分支,导致了错误。Git不知道要将更改推送到哪里。 -
设置上游分支并且推送被拒绝: 按照Git的建议,你试图设置上游分支并再次推送(
git push --set-upstream origin main),但推送被拒绝了,因为你的本地分支落后于远端对应的分支,意味着远端仓库中有你本地没有的更改。Git为了保护这些更改不被不经整合直接覆盖而阻止了推送。 -
尝试拉取没有跟踪信息的分支: 当你尝试拉取远端的更改来更新你的本地分支(
git pull)时,遇到了另一个错误,因为Git不知道要从哪个分支拉取。这是因为,尽管你在推送尝试中试图设置上游分支,但推送没有成功,留下你当前分支没有跟踪信息。
要解决这些问题并成功更新你的仓库,请按照以下步骤操作:
第一步:设置上游分支
首先,显式设置你的本地分支以跟踪远端的主分支,这个操作告诉Git你的本地分支在远程服务器上对应哪个分支。
bashgit branch --set-upstream-to=origin/main main第二步:从远端拉取更改
设置跟踪信息后,你需要从远端仓库拉取最新的更改。这个操作将尝试将远端的更改合并到你的本地分支。
bashgit pull origin main -