默认情况下,git 跟踪分支



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

当我运行以下内容时:

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

但是我的新分支不存在foo是 Bitbucket,除非我将远程和分支添加到带有git push origin foo的命令中。 即便如此,它也会开始跟踪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> $

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

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

它会起作用。

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

git config push.default current

最新更新