简体   繁体   English

远程分支中的 GIT 错误:无法从现有远程分支推送或拉取

[英]GIT error in remote branch: cannot push or pull from existing remote branch

I am new to git, but I don't think I am doing anything wrong.我是 git 新手,但我不认为我做错了什么。 gitk shows that the local branch is 1 step ahead of the remote branch: gitk 显示本地分支比远程分支领先一步:

branch1
|
|
remotes/origin/branch1
|
|
master-- remotes/origin/master

But when I do git push origin branch1 it shows但是当我做git push origin branch1它显示

error: failed to push some refs to <remote-url>

Although, git push origin master works.虽然, git push origin master有效。 If I do git pull origin branch1 , I get如果我做git pull origin branch1 ,我得到

fatal: couldn't find remote ref branch1

Here is the output for git remote show origin :这是git remote show origin的输出:

* remote origin
  Fetch URL: <remote-url>
  Push  URL: <remote-url>
  HEAD branch: (unknown)
  Remote branches:
    branch1         tracked
    master          tracked
  Local branches configured for 'git pull':
    branch1         merges with remote branch1
    master          merges with remote master
  Local ref configured for 'git push':
    master pushes to master (up to date)

Suspiciously there is a missing configuration for the local ref of branch1 for git push .令人怀疑的是, git push的 branch1 的本地引用缺少配置。 Is that the problem ?这是问题吗? How do I fix it ?我如何解决它 ?

It seems branch1 is your local branch and it's not available in your remote repository.似乎branch1是您的本地分支,它在您的远程存储库中不可用。

If this is the case, then try the following command and see if it works:如果是这种情况,请尝试以下命令,看看它是否有效:

git push -f origin branch1

Here, we are forcing to push branch1 .在这里,我们强制推送branch1 Keep in mind it is risky if the branch1 already exist in remote repository because it will override that remote branch.请记住,如果branch1已存在于远程存储库中,则存在风险,因为它将覆盖该远程分支。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM