我想改变Git的默认远程分支目标,这样我就可以

git push

而不是:

git push upstream

目前,这是设置为原始远程,我想将其设置为不同的远程。

我试图删除原(克隆)远程

git remote rm origin

把原来的遥控器弄掉了。但不能解决git推送的问题。我仍然得到:

fatal:没有配置推送目标。对象中指定URL 命令行或配置远程存储库使用…

我还试着玩:

git remote set-url --push myfork origin

和其他选项,但似乎没有工作(可能是因为我删除了起源远程太快?)

下面的答案我试着改变:

git config push.default upstream (or matching)

但这两种方法都不奏效。


当前回答

git push -u origin head是我正在寻找的。


以下是它为我解决的问题:

fatal: The current branch task/PLAT-1924-datagrid-tool-panel-scrollbar has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin task/PLAT-1924-datagrid-tool-panel-scrollbar

➜  frontend git:(task/PLAT-1924-datagrid-tool-panel-scrollbar) git push -u origin head

我可以使用键盘快捷键或别名来输入Git push -u origin head,而不是使用我的鼠标向上复制Git的建议(Git push -set-upstream origin task/PLAT-1924-datagrid-tool-panel-scrollbar),然后粘贴并运行它,它不需要是分支特定的。

更新:奇怪的是,今天我得到了这个错误。在上面的命令中将小写字母改为大写字母就解决了这个问题。

感谢https://stackoverflow.com/a/23402125/470749。

其他回答

如果你使用git push origin -u localBranchName:remoteBranchName,然后依次执行git push命令,你会得到origin不存在的错误,然后执行以下步骤:

Git remote -v

看看有没有我不在乎的遥控器。 用git远程删除名字

Git配置

寻找可能存在的旧遥控器的迹象。 寻找pushdefault:

[remote]
  pushdefault = oldremote

更新旧远程值并保存。

Git push现在应该工作了。

git push -u origin head是我正在寻找的。


以下是它为我解决的问题:

fatal: The current branch task/PLAT-1924-datagrid-tool-panel-scrollbar has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin task/PLAT-1924-datagrid-tool-panel-scrollbar

➜  frontend git:(task/PLAT-1924-datagrid-tool-panel-scrollbar) git push -u origin head

我可以使用键盘快捷键或别名来输入Git push -u origin head,而不是使用我的鼠标向上复制Git的建议(Git push -set-upstream origin task/PLAT-1924-datagrid-tool-panel-scrollbar),然后粘贴并运行它,它不需要是分支特定的。

更新:奇怪的是,今天我得到了这个错误。在上面的命令中将小写字母改为大写字母就解决了这个问题。

感谢https://stackoverflow.com/a/23402125/470749。

非常简单,我把这里的一些很棒的评论和我自己的研究拼凑在一起。

首先,检查您想要绑定到远程分支的本地分支:

git checkout mybranch

下一个:

git branch -u origin/mybranch

地点:

git branch -u {remote name}/{branch name}

你会收到一条消息:

"Branch mybranch set up to track remote branch mybranch from origin."

在git的手册中,你会发现以下内容:

remote.pushDefault 默认情况下要推到的遥控器。覆盖分支。<名称>。所有分支的远程,并被分支覆盖。用于指定分支的pushRemote。

Git remote set-url——push origin应该可以工作,正如你提到的,但你需要显式地提供url,而不是一个替代的远程名称,例如。

git remote set-url --push origin git@github.com:contributor/repo.git

您可以通过执行git remote -v来确认这是否有效。如。

λ ~/go/src/github.com/stretchr/testify/ master git remote -v
fork    git@github.com:contributor/testify.git (fetch)
fork    git@github.com:contributor/testify.git (push)
origin  git@github.com:stretchr/testify (fetch)
origin  git@github.com:contributor/testify.git (push)