我想改变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)

但这两种方法都不奏效。


当前回答

就像医生说的:

当命令行没有使用<repository>参数指定推入位置时,请使用branch.*。参考当前分支的远程配置来确定推送位置。如果缺少配置,则默认为origin。

其他回答

就像医生说的:

当命令行没有使用<repository>参数指定推入位置时,请使用branch.*。参考当前分支的远程配置来确定推送位置。如果缺少配置,则默认为origin。

只是澄清一下(在ubuntu 12.04上使用git 1.7.9.5版本):

Git将添加/删除遥控器。这些是带有服务器的git远程实例。

git remote add myremote git://remoteurl

然后你可以像这样获取git存储库:

git fetch myremote

这似乎创建了一个名为“myremote”的分支,但是分支的远程并没有自动设置。要做到这一点,你必须做到以下几点:

首先,验证您是否有这个问题,即。

git config -l | grep myremote

你会看到如下内容:

remote.myremote.url=git://remoteurl
remote.myremote.fetch=+refs/heads/*:refs/remotes/myremote/*
branch.myremote.remote=.
branch.myremote.merge=refs/heads/master

如果看到branch.myremote.remote=。,那么你应该继续:

git config branch.myremote.remote myremote
git checkout myremote
git pull

您现在应该与远程存储库保持一致,您的拉/推操作应该绑定到适当的远程。您可以以这种方式在每个分支切换遥控器。[注][1]

According to a The Official Git Config Documentation, you can set up a default push branch (just search remote.pushdefault on that page), however keep in mind that this will not affect repositories/branches which already exist, so this will work but only for new repositories/branches. You should remember that --global will set user-specific repository defaults (~/.gitconfig), --system will set system-wide repository defaults (/etc/gitconfig), and no flag will set configuration options for the current repository (./.gitconfig).

另外需要注意的是,push.default配置选项用于配置ref-spec行为,而不是远程行为。

[1]: git branch——set-upstream myotherremote通常在这里工作,但是git会抱怨如果git branch——set-upstream myremote被使用,它将不会将一个分支设置为自己的远程。然而,我认为这是不正确的行为。

看看你的repo中的.git/config可能会很有帮助,它会列出所有的遥控器,以及每个分支的默认遥控器

eg.

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    url = git@gitea.xxx.be:fii/web2016.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master
[branch "bugfix/#8302"]
    remote = origin
    merge = "refs/heads/bugfix/#8302"
[branch "feature/#8331"]
    remote = origin
    merge = "refs/heads/feature/#8331"
[remote "scm"]
    url = https://scm.xxx.be/git/web2016bs.git
    fetch = +refs/heads/*:refs/remotes/scm/*

您可以对该文件进行手动更改,以删除不需要的远程,或者更新您拥有的不同分支的默认远程

注意!当更改或删除遥控器时,请确保在这个配置文件中更新对它的所有引用

可以使用git push -u <remote_name> <local_branch_name>来设置默认的上游。更多细节请参见git push的文档。

使用Git 2.3.2…

git branch --set-upstream-to myfork/master

现在状态,推和拉都指向myfork远程