4

I've searched a bit, but can't seem to find the answer.

On two the boxes I have access to, when I do a "git push --dry-run origin mytestbranch", I get the following result:

To git@bitbucket.org:rien/test.git
 * [new branch]      test -> test

However, on my macbook, when I try the same command, I get the following result:

To git@bitbucket.org:rien/test.git
   417248a..cf7d564  test -> master

Only when I explicitly say push to the test origin branch (git push --dry-run origin test:test) does it work as expected.

How do I change it so that a basic git push --dry-run bb test will push to a newly created remote branch and not to master?

I created the test branch on both boxes with a git checkout -b test origin/master

Edited to add: - both branches have a git config push.default set to tracking.

I specifically want to know how to configure git so that when i type git push origin test that it acts the same as git push origin test:test

rien
  • 43
  • 5

1 Answers1

6

Check if there is a difference in push policy:

git config push.default

I suspect on the first box, the push is "simple"

git config push.default simple

Check also the upstream branch of the test branch on the second branch:

git config branch.test.merge

On the second branch, it might not be defined (hence the default value master)

You can set it explicitly:

git checkout test
git branch -u origin/test
# or
git push -u origin test:test

The OP rien adds in the comments:

After noticing I had a different version of git for those boxes, I looked around some more and found that if I set the push.default to simple or matching for the git version 1.9.3, the git push origin test works as expected.
It seems like the tracking push.default is deprecated for this version of git so it did not understand it.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • For both boxes, when I type `git config push.default'`, the result is `tracking`. On the second branch, the result of `git config branch.test.merge` is `refs/heads/master` and nothing on the first branch. However, when I try to set it explicitly, I receive the following error: `error: the requested upstream branch 'origin/test' does not exist`. How do I change it so that when I create a branch with `git checkout -b test origin/master` that the default `git push origin test` behavior is `git push origin test:test` ? – rien Dec 06 '14 at 16:05
  • Simply do a git push -u origin test:test – VonC Dec 06 '14 at 17:57
  • I understand I can do that. I'd more specifically like to know how I can configure git so the default behavior of `git push origin test` behaves the same way as `git push -u origin test:test`. – rien Dec 06 '14 at 18:09
  • It will behave that way: only the first push needs to use the -u option: see my explanations at http://stackoverflow.com/a/17096880/6309 – VonC Dec 06 '14 at 18:11
  • Could you explain why in the first push for the first box I'm on, I wouldn't need to specify `git push -u origin test:test` then and `git push origin test` works? Why do I need to specify this on my second box (my macbook) specifically? Why does it work differently and how do I configure the second box (my mac) to work the same as the first box? – rien Dec 06 '14 at 18:43
  • @rien is the git version the same on both boxes? – VonC Dec 06 '14 at 18:45
  • The one that works as expected has "git version 1.8.2.1", the other one has "git version 1.9.3 (Apple Git-50)". – rien Dec 06 '14 at 18:52
  • After noticing I had a different version of git for those boxes, I looked around some more and found that if I set the `push.default` to `simple` or `matching` for the git version 1.9.3, the `git push origin test` works as expected. It seems like the `tracking` `push.default` is deprecated for this version of git so it did not understand it. Thanks so much for your help. – rien Dec 06 '14 at 19:17
  • @rien great feedback! i have included it in the answer for more visibility. – VonC Dec 06 '14 at 19:32
  • @rien - `tracking` is not deprecated, it still works as of 2.2.0, it is now an undocumented synonym for `upstream`. – Andrew C Dec 06 '14 at 19:46
  • @AndrewC In that case, why is it that typing `git push origin test` with a `push.default` set to `tracking` result in a different behavior between git versions 1.8.2.1 and 1.9.3? In 1.8.2.1, the command will create a new branch `test` on `origin` while in 1.9.3, the command will merge the branch into `master`. – rien Dec 06 '14 at 19:52
  • @rien - possibly you have a different setting in your repository config file (.git/config) that is shadowing a setting in your ~/.gitconfig ? Or maybe it's because you are manually specifying the ref on the command line - with tracking set I just type `git push` and it knows I want to push my current branch to the upstream. – Andrew C Dec 06 '14 at 20:23