Create a new branch with tracking information

Here is my usual workflow:

  • create a new branch: git checkout -b foo
  • convey some things
  • do push: git push
  • angry that push is not working (no upstream dialing)
  • move the mouse to highlight git of the recommended command (still angry)
  • click upstream tuning: git push --set-upstream origin foo (anger subsides)

Instead of 4-6, I would like to do some work when creating a new branch locally (without having to make my branch open, so without clicking ), which kills steps 4. through 6. Is this possible?

Ideally, something like git checkout -b foo -t origin , which tells git that I plan to track a branch with the same name in origin .

What i tried

git checkout -b foo --set-upstream origin foo ~> error: unknown option 'set-upstream'

git checkout --track origin/foo ~> fatal: Cannot update paths and switch to branch 'foo' at the same time.

git checkout -b foo --track origin/foo ~> fatal: Cannot update paths and switch to branch 'foo' at the same time

git checkout -b foo --track ~> Branch foo set up to track local branch master.

+7
git
source share
3 answers

There is an answer to a slightly different topic that can help you in your workflow (not 100%).

You can do this with less input. First, change the way push works:

 git config --global push.default current 

This will output the origin my_branch part, so you can do:

 git push -u 

Which will create a remote branch with the same name and track it.

In fact, you can even omit -u , and it should still work.

+6
source share

If you want to configure the upstream in step 1. You violate the concept of git as a distributed version control system. You can do this with another version control system like svn .

Alternatively, you can use the -u flag on git push to set upstream before committing files.

 git branch branch-name git push -u origin branch-name ... git commit ... ... git push 
+1
source share

Isn't it as simple as git checkout branch-name without -b. This creates a remote tracking branch associated with the branch name in your source. Well, this is for me. What I do not understand about what does not work for you?

+1
source share

All Articles