git track默认分支

时间:2018-10-07 18:57:13

标签: git version-control bitbucket git-branch

默认情况下,我希望git始终跟踪origin上具有相同名称的分支,除非我为pushpull专门将上游分支设置为其他名称。但这不是我所看到的行为。

当我运行以下命令时:

$ git branch -b foo
$ git push
Everything up-to-date

但是我的新分支foo不存在是Bitbucket,除非我使用git push origin foo将remote和branch添加到命令中。即使这样,它也会开始跟踪push,但不会跟踪pull

user@host [~/git/repository] <foo> $ echo 'test' >> test.txt
user@host [~/git/repository] <foo> $ git add test.txt
user@host [~/git/repository] <foo> $ git commit -m 'test'
[foo 376b03b] test
 1 file changed, 1 insertion(+)
 create mode 100644 test.txt
user@host [~/git/repository] <foo> $ git push
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 277 bytes | 277.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote:
remote: Create pull request for foo:
remote:   https://bitbucket.host.com/projects/PROJ/repos/repository/compare/commits?sourceBranch=refs/heads/foo
remote:
To ssh://bitbucket.host.com:7999/proj/repository.git
   34c6308..376b03b  foo -> foo
user@host [~/git/repository] <foo> $ git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> foo

user@host [~/git/repository] <foo> $

我知道我可以将其设置为使用push跟踪pullgit push -u origin foo,但是我想知道是否可以设置一些配置值,以便默认情况下, push将始终推送到具有相同名称的origin上的分支,而pull将始终从具有相同名称的origin上的分支拉出,这样我就可以做到这一点:

$ git checkout -b foo
$ #make changes
$ git commit -am 'changes'
$ git push
$ #someone else makes changes
$ git pull

它将起作用。

1 个答案:

答案 0 :(得分:0)

使用current作为默认推送策略:

git config push.default current