0

If I'm working on a branch A and git checkout master and then make a new branch B with git branch B, will this new branch automatically make a tracked branch on the remote repo? Thus, whenever I push from this branch, it will push to a new remote branch 'B' on the remote repo.

akantoword
  • 2,824
  • 8
  • 26
  • 43
  • 1
    no, it will create when you push your data `git push origin your_branch` – D.Dimitrioglo Jun 20 '16 at 20:01
  • so doing this without the -u option will only create a remote branch that it pushes to once, correct? if I did include the -u option, the current branch will become a tracking branch that tracks the remote branch and automatically push to that branch without me having to designate it after typing 'git push' – akantoword Jun 20 '16 at 20:13

2 Answers2

2

No tracking branch is ever created automatically; it is a result of a direct user instruction.

I should point out that there are differences between creating a remote branch and creating a remote branch which is tracked locally. You can create a remote branch by pushing the branch you created right away, but that won't cause it to be tracked. You create a tracked branch one of two ways:

  • After the branch has been pushed and you are on the local branch you wish to track it with

    git branch --set-upstream-to=origin/branchname
    # or
    git branch -u origin/branchname
    
  • Before the branch has been pushed and you are on the branch you'd like to push

    git push -u origin branchname
    

For more nuance into the above two commands, this particular question provides a lot more detail.

Community
  • 1
  • 1
Makoto
  • 104,088
  • 27
  • 192
  • 230
  • just to be clear, the -u option makes your local branch track the newly create remote branch, so that you can conveniently push to it without having to designate the remote branch each time, correct? – akantoword Jun 20 '16 at 20:15
  • Depending on your [push options](https://git-scm.com/docs/git-config) (search for `push.default`), then that is absolutely correct. You're likely using the default "simple" so you don't have anything to worry about in that regard. – Makoto Jun 20 '16 at 20:19
1

The remote branch is created when you push, not when you create the local branch.

Andrew Rueckert
  • 4,858
  • 1
  • 33
  • 44