Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git track branch by default

By default, I would like git to always track a branch on origin with the same name, unless I specifically set the upstream branch to something else, for both push and pull. But that is not the behavior I am seeing.

When I run the following:

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

But my new branch foo does not exist is Bitbucket unless I add the the remote and branch to the command with git push origin foo. And even then, it will start tracking for push, but not 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> $

I know I can set it to track for both push and pull with git push -u origin foo, but I'm wondering if it's possible to set some config value so that, by default, push will always push to the branch on origin with the same name, and pull will always pull from the branch on origin with the same name, so that I can just do this:

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

And it will work.

like image 219
ewok Avatar asked Sep 14 '25 20:09

ewok


1 Answers

Use current as the default push strategy:

git config push.default current
like image 87
Jason Haslam Avatar answered Sep 16 '25 18:09

Jason Haslam