我有一个远程裸库中心。我只在总行工作。
下面这个错误消息的最后一句话让我想知道:我如何找到哪个是“当前分支的默认配置远程”?怎么设置呢?
[myserver]~/progs $ git remote -v
hub ~/sitehub/progs.git/ (fetch)
hub ~/sitehub/progs.git/ (push)
[myserver]~/progs $ git branch -r
hub/master
[myserver]~/progs $ cat .git/HEAD
ref: refs/heads/master
[myserver]~/progs $ git pull hub
You asked to pull from the remote 'hub', but did not specify
a branch. Because this is not the default configured remote
for your current branch, you must specify a branch on the command line.
你可以更简单地做到这一点,保证你的.gitconfig处于有意义的状态:
使用Git v1.8.0及以上版本
Git push -u hub master当push时,或:
Git分支-u hub/master
OR
(这将把当前签出分支的远程设置为hub/master)
Git分支——set-up - stream-to - hub/master
OR
(这将把名为branch_name的分支的远程设置为hub/master)
Git分支branch_name——set-upstream-to - hub/master
如果您使用的是v1.7。X或更早
你必须使用——set-upstream:
Git分支——set-upstream master hub/master
Git:哪个是分支的默认配置远程?
对于一个名为branch_name的分支,读取如下:
git config branch.branch_name.remote
细节
你可以通过git config branch.branch_name.remote通过编程方式读取任何给定分支的本地存储的远程跟踪远程名称。
假设您有一个名为main的分支,它跟踪的远程分支被设置为origin。在这种情况下,你的.git/配置文件将包含以下内容:
[branch "main"]
remote = origin
merge = refs/heads/main
运行:
git config branch.main.remote
...因此将读取该配置设置并返回remote。
您可以使用这些模式以编程方式读取或写入任何git配置变量,甚至是您自己发明或创建的变量。
例如:git config——global blametool。编辑器subl将这些行添加到全局~/的底部。gitconfig文件:
[blametool]
editor = subl
你可以通过git config blametool.editor读取变量subl。
这就是我如何为我的git blametool脚本设置一个blametool。