Automatic branch creation doesn't use -b (create) flag
Asked by Joe Rajewski:

New to bitbucket/Jira integrations, using VSCode + Powershell, on Windows \& Docker.

I'm familiar with when I don't have an existing branch, I need to pass the '-b' flag to force that branch to be created locally. However, I'm noticing when I create my branch inside the Jira interface (which is integrated w/ my Bitbucket repo), it's leaving that flag off. (See attached image) \& note the missing '-b' flag where it offers up the prepared copy/paste commands.

Referencing Git documentation, this command as displayed below will simply switch, not ALSO create. If the branch doesn't exist it can't switch \& doesn't auto create. I can obviously manage this manually, but shouldn't any 1st time story be using the '-b' flag by default, is this something I can configure on my end \& haven't found documentation on?

![Screen Shot 2020-11-10 at 9.36.07 AM.png](/t5/image/serverpage/image-id/117743iD02E33D56243E08F/image-size/large?v=v2&px=999 "Screen Shot 2020-11-10 at 9.36.07 AM.png")


Answers:
author: Dario B
body: Hello [@Joe Rajewski](/t5/user/viewprofilepage/user-id/3615089) ,

I have moved this question to the Bitbucket section since when you click on the "Create New Branch" link in the Jira issue view this is actually redirecting to:

* [https://bitbucket.org/branch/create?issueKey=\[ISSUEKEY\]\&issueType=\[ISSUETYPE\]\&issueSummary=\[SUMMARY](https://bitbucket.org/branch/create?issueKey=[ISSUEKEY]&issueType=[ISSUETYPE]&issueSummary=[SUMMARY)\]

Once this has been said, please notice that the branch has already been created when the dialog you pasted the screenshot of is displayed.

Indeed:

1. when you click on create branch, a first dialog is displayed asking for more information:  
   ![Create-Branch-JRACLOUD.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/118672iCBD749394972F028/image-dimensions/208x163?v=v2 "Create-Branch-JRACLOUD.jpg")
2. Then, only after clicking on "Create" and therefore after the branch has already been created, the dialog from your screenshot is showed:  
   ![02-Create-Branch-BCLOUD.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/118673i00F72EF73295C595/image-dimensions/255x154?v=v2 "02-Create-Branch-BCLOUD.jpg")

Cheers,  
Dario

comments: author: Joe Rajewski
body: Correct, you replicated my experience. Shouldn't the -b flag be added (per Git documentation) here to take care of 1st time local branch creation? Is this configurable under my account \& I'm not aware (if so, where?).. Any help would be appreciated.


author: Dario B
body: Hi [@Joe Rajewski](/t5/user/viewprofilepage/user-id/3615089) ,

I might not be the best person to answer this question (I only got it since it was in the Jira section) however, from what I can read in the Bitbucket documentation for [git checkout](https://www.atlassian.com/git/tutorials/using-branches/git-checkout), in modern versions of Git you don't need to create a new branch, you can checkout the remote one like it was local:
>
> Git Checkout a Remote Branch {#toc-hId--1298996348}
> ---------------------------------------------------
>
> When collaborating with a team it is common to utilize remote repositories. These repositories may be hosted and shared or they may be another colleague's local copy. Each remote repository will contain its own set of branches. In order to checkout a remote branch you have to first fetch the contents of the branch.
>
>     git fetch --all
>
> In modern versions of Git, you can then checkout the remote branch like a local branch.
>
>     git checkout 
>
> Older versions of Git require the creation of a new branch based on the `remote`...
>
> \[...\]

In other words, in modern versions of Git you don't need to use the -b flag. I have tested this locally in order to confirm, and it works as documented:

```
$ git fetch && git checkout TSP-23-one-more
From bitbucket.org:xxxxxx/test-repo-1
* [new branch] TSP-23-one-more -> origin/TSP-23-one-more
Branch 'TSP-23-one-more' set up to track remote branch 'TSP-23-one-more' from 'origin'.
Switched to a new branch 'TSP-23-one-more'
```

Cheers,  
Dario


Tags: cloud

git