I have a remote bare repository hub
. I work only in the master
branch. The last sentence of this error message below makes me wonder: How do I find out which is the "default configured remote for your current branch"? And how do I set it?
我有一个远程裸存储库集线器。我只在总行工作。下面这条错误消息的最后一句话让我想知道:我如何才能知道“当前分支的默认配置远程”是什么?如何设置它呢?
[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.
3 个解决方案
#1
215
Track the remote branch
跟踪远程分支
You can specify the default remote repository for pushing and pulling using git-branch’s track option. You’d normally do this by specifying the --track option when creating your local master branch, but as it already exists we’ll just update the config manually like so:
可以使用git-branch的跟踪选项指定默认远程存储库。在创建本地主分支时,通常需要指定-track选项,但由于它已经存在,我们将手动更新配置,如下所示:
Edit your .git/config
编辑你的. /配置
[branch "master"]
remote = origin
merge = refs/heads/master
Now you can simply git push and git pull.
现在您可以简单地git push和git pull。
[source]
(来源)
#2
247
You can do it more simply, guaranteeing that your .gitconfig
is left in a meaningful state:
您可以做得更简单,确保您的.gitconfig处于有意义的状态:
Using Git version v1.8.0 and above
git push -u hub master
when pushing, or:git branch -u hub/master
在推的时候git push -u hub master,或者:git分支-u hub/master。
OR
(This will set the remote for the currently checked-out branch to hub/master
)git branch --set-upstream-to hub/master
(这将把当前签出的分支设置为hub/master) git分支——set-up -to - hub/master。
OR
(This will set the remote for the branch named branch_name
to hub/master
)git branch branch_name --set-upstream-to hub/master
(这会将名为branch_name的分支设置为hub/master) git分支branch_name——set- upstreamto hub/master
If you're using v1.7.x
or earlier
you must use --set-upstream
:git branch --set-upstream master hub/master
您必须使用——set- upper: git分支——set- upper master hub/master
#3
20
For the sake of completeness: the previous answers tell how to set the upstream branch, but not how to see it.
为了完整性起见:前面的答案告诉我们如何设置上游分支,而不是如何查看它。
There are a few ways to do this:
有几种方法可以做到这一点:
git branch -vv
shows that info for all branches. (formatted in blue in most terminals)
git分支-vv显示了所有分支的信息。(大多数终端采用蓝色格式)
cat .git/config
shows this also.
cat .git/config也显示了这一点。
For reference:
供参考:
- how do I get git to show me which branches are tracking what?
- 如何让git显示哪些分支在跟踪什么?
- What is this branch tracking (if anything) in git?
- 在git中这个分支跟踪(如果有的话)是什么?
#1
215
Track the remote branch
跟踪远程分支
You can specify the default remote repository for pushing and pulling using git-branch’s track option. You’d normally do this by specifying the --track option when creating your local master branch, but as it already exists we’ll just update the config manually like so:
可以使用git-branch的跟踪选项指定默认远程存储库。在创建本地主分支时,通常需要指定-track选项,但由于它已经存在,我们将手动更新配置,如下所示:
Edit your .git/config
编辑你的. /配置
[branch "master"]
remote = origin
merge = refs/heads/master
Now you can simply git push and git pull.
现在您可以简单地git push和git pull。
[source]
(来源)
#2
247
You can do it more simply, guaranteeing that your .gitconfig
is left in a meaningful state:
您可以做得更简单,确保您的.gitconfig处于有意义的状态:
Using Git version v1.8.0 and above
git push -u hub master
when pushing, or:git branch -u hub/master
在推的时候git push -u hub master,或者:git分支-u hub/master。
OR
(This will set the remote for the currently checked-out branch to hub/master
)git branch --set-upstream-to hub/master
(这将把当前签出的分支设置为hub/master) git分支——set-up -to - hub/master。
OR
(This will set the remote for the branch named branch_name
to hub/master
)git branch branch_name --set-upstream-to hub/master
(这会将名为branch_name的分支设置为hub/master) git分支branch_name——set- upstreamto hub/master
If you're using v1.7.x
or earlier
you must use --set-upstream
:git branch --set-upstream master hub/master
您必须使用——set- upper: git分支——set- upper master hub/master
#3
20
For the sake of completeness: the previous answers tell how to set the upstream branch, but not how to see it.
为了完整性起见:前面的答案告诉我们如何设置上游分支,而不是如何查看它。
There are a few ways to do this:
有几种方法可以做到这一点:
git branch -vv
shows that info for all branches. (formatted in blue in most terminals)
git分支-vv显示了所有分支的信息。(大多数终端采用蓝色格式)
cat .git/config
shows this also.
cat .git/config也显示了这一点。
For reference:
供参考:
- how do I get git to show me which branches are tracking what?
- 如何让git显示哪些分支在跟踪什么?
- What is this branch tracking (if anything) in git?
- 在git中这个分支跟踪(如果有的话)是什么?