如果我在一个本地分支上,该分支不跟踪任何远程分支,并且我执行以下命令:
git fetch
假设我在$GIT_DIR/config
中定义了几个远程仓库,从哪个远程仓库进行获取fetch操作?
我尝试从手册页面中找到答案,但是这一点对我来说不太清楚。
另外:如何更改默认远程仓库而不进行本地分支追踪?
origin
。如果没有名为 origin 的远程存储库,则会报错。fatal: No remote repository specified. Please, specify either a URL or a
remote name from which new revisions should be fetched.
另外:如何更改默认远程仓库而不使本地分支跟踪它?
您可以将该仓库重命名为“origin”以使其成为默认值。
注意:如果当前分支已经在不同的远程仓库上指定了上游,则此方法无效。从git help fetch
:
当未指定远程仓库时,默认使用origin远程仓库,除非为当前分支配置了上游分支。
在这种情况下,您可以通过编辑.git/config
中配置的分支的remote
字段来更改上游分支以使用origin
。
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = git@github.com:project.git
因此,代码从此处列出的URL获取。
git remote -v
(查看所有)或 git remote get-url origin
(检查默认值)。 - ADTC它将获取源远程库。这是您执行 GIT clone
命令的第一个远程库。
git clone
,而是事后添加了远程地址(称为“origin”或其他名称)。 - mwfearnley以下是一些别名,可以用于编程:
branch-name = "symbolic-ref --short HEAD" # https://dev59.com/Hm025IYBdhLWcg3wCxZN#19585361
branch-remote-fetch = !"branch=$(git branch-name \"$1\") && git config branch.\"$branch\".remote || echo origin #"
branch-remote-push = !"branch=$(git branch-name \"$1\") && git config branch.\"$branch\".pushRemote || git config remote.pushDefault || git branch-remote-fetch #"
branch-url-fetch = !"remote=$(git branch-remote-fetch \"$1\") && git remote get-url \"$remote\" #" # cognizant of insteadOf
branch-url-push = !"remote=$(git branch-remote-push \"$1\") && git remote get-url --push \"$remote\" #" # cognizant of pushInsteadOf
branch-name
,允许传递单个参数:branch-current = "symbolic-ref --short HEAD" # https://dev59.com/Hm025IYBdhLWcg3wCxZN#19585361
branch-names = !"[ -z \"$1\" ] && git branch-current 2>/dev/null || git branch --format='%(refname:short)' --contains \"${1:-HEAD}\" #" # https://dev59.com/Hm025IYBdhLWcg3wCxZN#19585361
branch-name = !"br=$(git branch-names \"$1\") && case \"$br\" in *$'\\n'*) printf \"Multiple branches:\\n%s\" \"$br\">&2; exit 1;; esac; echo \"$br\" #"
git fetch
时,默认情况下将使用该远程仓库。 - ntc2origin
时,我曾经遇到过git fetch
静默失败的情况。它没有任何致命错误或任何信息。它只是立即退出到提示符。一旦我将远程库重命名为origin
,fetch
命令就可以从远程库获取了。 - ADTC