不能推本地更改现有的远程分支(Can't push local changes to an

2019-07-31 11:40发布

有一个称为“我的遥控”远程分支,我以前推到没有问题。 到今天为止,我不能推,我得到不同的错误。

我第一次错误是:

 hint: Updates were rejected because a pushed branch tip is behind its remote hint: counterpart. If you did not intend to push that branch, you may want to hint: specify branches to push or set the 'push.default' configuration hint: variable to 'current' or 'upstream' to push only the current branch. 

我做了一些研究,并运行此希望它能解决的问题:

git config push.default tracking

跑,我又跑了推后:

git push https://github.com/someurl/mybranch.git

我得到了以下错误:

pushing to remote 'https://github.com/someurl/mybranch.git', which is not the upstream of
your current branch 'my-remote', without telling me what to push
to update which remote branch.

我曾尝试运行以下命令:

git push master:my-remote https://github.com/someurl/mybranch.git

但是却对我说:

fatal: remote part of refspec is not a valid name in https://github.com/someurl/mybranch.git

Answer 1:

如果你想推的我的遥控器远程分支的主分支,正确的语法是:

 git push https://github.com/someurl/mybranch.git master:my-remote 

(第一:远程回购参考,操作的Refspec,从git push手册页 )

关于你提到的第一个错误信息,如果真的没有告诉你合并,那么git pull --rebase可能已经需要。
或者至少是:

 git config --global push.default current

(正如在提到“ 配置GIT中只会把当前分支 ”)。

如果你是在当地的分支机构“ my-remote ”(这是情况下,根据该命令),你可以确保上游分支是通过使设置:

git push -u https://github.com/someurl/mybranch.git my-remote:my-remote


Answer 2:

有9个步骤来推进到一个现有的混帐回购协议。

我想“混帐推--set上游起源大师”,并得到了以下错误:

C:\Users\User\Documents\Visual Studio 2013\Projects\app\User-app-40d72a288916>git push --set-upstream origin master
Password for 'https://User@bitbucket.org':
To https://User@bitbucket.org/User/app.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://User@bitbucket.org/User/
app.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first merge the remote changes (e.g.,
hint: 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

然后,我尝试“混帐拉”,并获得最新的变化:

C:\Users\User\Documents\Visual Studio 2013\Projects\app\User-app-40d72a288916>git pull
Password for 'https://User@bitbucket.org':
warning: no common commits
remote: Counting objects: 344, done.
remote: Compressing objects: 100% (275/275), done.
remote: Total 344 (delta 45), reused 336 (delta 41)
Receiving objects: 100% (344/344), 15.91 MiB | 43.00 KiB/s, done.
Resolving deltas: 100% (45/45), done.
From https://bitbucket.org/User/app
 * [new branch]      master     -> origin/master
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details

git pull <remote> <branch>

如果要设置这个分支你可以这样做跟踪信息:

git branch --set-upstream-to=origin/<branch> master

我做了一个“混帐推”和更改失败:

C:\Users\User\Documents\Visual Studio 2013\Projects\app\User-app-40d72a288916>git push origin master
Password for 'https://User@bitbucket.org':
To https://User@bitbucket.org/User/app.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://User@bitbucket.org/User/
app.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

“混帐添加-A”和“git的承诺”,没有工作,因为没有什么承诺。

C:\Users\User\Documents\Visual Studio 2013\Projects\app\User-app-40d72a288916>git add -A

C:\Users\User\Documents\Visual Studio 2013\Projects\app\User-app-40d72a288916>git commit

在分支主什么承诺,工作目录干净

“GIT中分支--set-上游到原点= /主主”似乎可以解决问题。

C:\Users\User\Documents\Visual Studio 2013\Projects\app\User-app-40d72a288916>git branch --set-upstream-to=origin/master master
Branch master set up to track remote branch master from origin.

然而,“混帐推起源大师”,没有工作,因为当前分支的末端是它背后的远程副本。

C:\Users\User\Documents\Visual Studio 2013\Projects\app\User-app-40d72a288916>git push origin master
Password for 'https://User@bitbucket.org':
To https://User@bitbucket.org/User/app.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://User@bitbucket.org/User/
app.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

这就需要一个“混帐拉”合并回购的。

C:\Users\User\Documents\Visual Studio 2013\Projects\app\User-app-40d72a288916>git pull
Password for 'https://User@bitbucket.org':
Merge made by the 'recursive' strategy.

执行“混帐拉”后,需要“混帐推起源大师”正是得到同步吩咐在Visual Studio插件的Git工作。

C:\Users\User\Documents\Visual Studio 2013\Projects\app\User-app-40d72a288916>git push origin master
Password for 'https://User@bitbucket.org':
Counting objects: 5, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 539 bytes | 0 bytes/s, done.
Total 4 (delta 2), reused 0 (delta 0)
To https://User@bitbucket.org/User/app.git
   40d72a2..9748b8b  master -> master

C:\Users\User\Documents\Visual Studio 2013\Projects\app\User-app-40d72a288916>


文章来源: Can't push local changes to an existing remote branch