0

I am always pushing my code to the same upstream repo. I would like to set up git so that when I create a new branch with git checkout -b foo, the upstream for branch foo will automatically push to and pull from the branch foo on the origin repo.

Is this possible?

benhsu
  • 5,346
  • 8
  • 39
  • 47
  • One problem: `git checkout -b foo` creates and checks out a new branch called `foo`. How can you be sure, at the time of creating that branch, that a branch called `foo` already exists on `origin`? – jub0bs Jun 30 '15 at 14:07
  • On the other hand, if the remote-tracking branch `origin/foo` exists, you can simply run `git checkout -b foo origin/foo`, which will do what you want, i.e. set the upstream of the local `foo` branch to `origin/foo`. – jub0bs Jun 30 '15 at 14:09
  • Jubobs, I'm gonna try putting that in my git alias – benhsu Jun 30 '15 at 15:01
  • Good call, if that's convenient for you. Have a look at this related question: http://stackoverflow.com/questions/17847213/how-to-configure-git-push-to-automatically-set-upstream-without-u – jub0bs Jun 30 '15 at 15:03
  • possible duplicate of [Git set tracking branch while offline](http://stackoverflow.com/questions/30602769/git-set-tracking-branch-while-offline) – Byte Lab Jun 30 '15 at 16:12
  • possible duplicate of [Why do I need to do \`--set-upstream\` all the time?](http://stackoverflow.com/questions/6089294/why-do-i-need-to-do-set-upstream-all-the-time) – Sascha Wolf Jul 02 '15 at 13:55

0 Answers0