The Wayback Machine - https://web.archive.org/web/20220604140152/https://github.com/github-community/community/discussions/12290
Skip to content
This is a ✨special✨ repository containing the organization level discussions for github-community. Everything posted here will also be visible at the organization level.

🆕 Create a branch for an issue in public beta #12290

Unanswered
dipree asked this question in Issues
🆕 Create a branch for an issue in public beta #12290
Mar 2, 2022 · 53 answers · 68 replies

In an issue, you can now create a branch for that issue and start work right away. In the sidebar of an issue, branches connected to the issue are shown in the "Development" section, which has replaced "Linked pull requests". When you create a pull request for one of these branches, it is automatically linked to the issue. You can learn more about the functionality in our documentation.

Addresses github/roadmap#218 on our public roadmap.

We can't wait for you to try it out! Let us know what you think here in Discussions.

:octocat: 🐳

Replies

53 suggested answers
·
68 replies

this is nice. but i would prefer like gitlab has it, that it creates both a branch and a PR for you. one of the things that annoys me a lot when working on github. i like to take notes about my work in the PR but on github i can't do that before i already have 1 commit on the branch, something which doesn't always happen so fast.

8 replies
@dipree

Thank you for the feedback, this is not directly related to the new functionality but I will make sure to pass it on to the right folks.

@pietrovismara

@Powersource What I do is push an empty commit on the new branch in order to be able to create the PR. Not ideal, but doable.

@robvanderleek

Not sure if I'm allowed to post this here but I guess there will always be features not covered by the platform itself; There's an App/Action called Create Issue Branch that supports automatically opening (draft) PRs.
FD: I'm the author of that app.

It would be pretty awesome if it were possible to link an existing branch from another repository within the scope of the organization.

Where I work there is a certain repository of tasks where it is not possible to link Pull Requests or Branches because the projects are done in another repository, this would be an excellent addition.

6 replies
@dipree

Thank you for bringing it up. Linking existing branches is not possible yet but your request is noted. To mitigate the problem in the meantime, you can create a branch from the repository that contains the issue and select a separate repository to create the branch in.

@meysam101

Makhzan man

@tpak

We have the same challenge as @DevNatan - @dipree your suggestion, while interesting, means now 2 branches need to be tracked, merged, and cleaned up.

Just noticed that when I do create a PR from the branch, it automatically links it to the issue and marks the issue for autoclosing when the PR is merged. This is something we don't want in our org so this is a bit annoying. E.g. we already have to write "for #123" in PRs instead of "fixes #123" to avoid the autoclosing, and this adds another thing we have to dodge.

2 replies
@dipree

Again, good feedback, keep it coming. This is not directly related but I will make sure to pass it on.

@duanestrong

Now that I have been using it for a while I agree this is way too much almost hidden automation I can't control. I am unlinking the issue on the PR just before merge to stop it from auto closing the issue. Maybe options on the PR merge page on how you want to deal with linked issues?

Finally! That's exactly the feature I've been waiting for - thanks for adding this to GitHub.

One small issue: when the issue title contains special characters (e.g., markdown backticks), it would be amazing if branch name could sanitize those out.

Screen Shot 2022-03-02 at 10 01 32 AM

6 replies
@dipree

Thanks @nicbet, noted!

@meysam101

Ok

@meysam101

Mkkhbyggu

Not within the scope of this feature currently, but in the future it would be neat to see:

  • The existence of any branches associated with the issue appear in the main "Issues" page, similar to how the PR icon shows up. This would help to differentiate between active and inactive issues (similar to Azure Devops)
  • The creation of a development branch show up in the timeline of a specific issue, similar to other events (commits, comments, tags, etc.)

Great work guys

0 replies

I can't assign existing branch (new-design) to the issue: TomaszGasior/RadioLista-v3#116. It's only possible to create branches and choose PRs, no way to just select existing bare branch.

0 replies

It would be great if we can configure some sort f regex when it comes to the naming convention of the branch as well as limit or unlimit the name length of the branch

For example.

bug/issue-name/123
or to kind of generalise that
[label]/name/[ticket number]

7 replies
@mathze

Not quite sure if this fall into your suggestion, but I also would appreciate a way to configure the branch-name on a per repository level.
E.g. I like to have my branches related to issues under /issues/[ticket number]. Actually I've to insert it manually and delete the generated title.
Maybe something similar to intellij's task pattern placeholders?

@Gerben-T

I think a quick win here would be a customizable prefix for the branch name.
Using the example above you would configure your prefix as bug/name/.
Let's say the ticket title is "Fix login bug", the branch would become bug/name/fix-login-bug.

In the long run i would also prefer some more customization, maybe in the form of using variables in the prefix and maybe even add a suffix.
Couple variables could be:

[label][0]  = First label assigned to ticket (index 0 can be increased to match other labels)
[name]      = Title of the ticket
[number]    = Number of the ticket

This way we can define something like this:

[label][0]/[number]-[name]

which could translate to

feature/123-fix-login-bug 
@stiliajohny

Any regex around the branch name would be a win :)
Perhaps having the option to drag and drop different attributes as mentioned on @Gerben-T comment

[label][0]  = First label assigned to ticket (index 0 can be increased to match other labels)
[name]      = Title of the ticket
[number]    = Number of the ticket

This way we can define something like this:

[label][0]/[number]-[name]

Could we get the option to move a projects story to the correct column when using the create branch feature?

A story/issue is in the Todo column. Once the branch is created the story is then moved to the "In Progress" column.

1 reply
@dipree

That's indeed a great suggestion. This currently limited by the Projects Beta which doesn't allow this yet. But once it does we can support this is an option.

We'd like to see the ability to configure a default repository destination.

We've got a two-repo structure for all projects to separate project management and source*.

So for a ticket in the foo-project repo, branches will always be in the foo-source repo. Now we can use the dropdown, but making it configurable will avoid occurences of distractingly creating it in the wrong repo, and just reduce the number of clicks we have to do every time.


On a related note, being able to configure the default branch would also be nice.

Something a bit more complex: configuring the default branch source (and branch name) based on labels.
Examples:

  • a hotfix label means a branch named hotfix/1234-broken-thing off the main branch.
  • a feature label means a branch named feature/5678-awesome-new-thing created off the nightly branch.
1 reply
@dillingham

If not by label, then at-least multiple branch name templates with a title that becomes a button in the modal

Love the feature! But I think I ran into a bug?

My issue title is something like "🐛 [Foo] Bar" which suggests a branch name 42-🐛-foo-bar. Which works. But after checking out the branch locally, I'm not able to push, it fails without any helpful error message

1 reply
@dipree

We are now sanitizing the branch name more strictly so this shouldn't happen anymore.

This is amazing, it working very good! But have a stranger behavior, when have " - " in name of issue, type "Product - Create Variants", in name of branch get 3 "-", type "52-produtos---create-variants"

1 reply
@dipree

Thanks for the feedback, this has been fixed.

Linking to an existing branch would be great.

2 replies
@ali-masaaf

You can link an existing branch from here

image-14

@williamd5

That links an existing PR, not a branch

I like this feature, and it would be better if we can add the feature type to the branch name like <ref>-<type>-<issue name> instead of <ref>-<issue name> the type could be a value like feat/bug/docs/...

0 replies

Not sure if I'm allowed to post this again but I guess there will always be features not covered by the platform itself.
This is my second (and last) post here to inform GitHub users there's an App/Action called Create Issue Branch that supports many features requested above, such as:

FD: I'm the author of that app.

I think the current "Create a branch" functionality in the platform is a great starting point for most development workflows (and most likely sufficient for many projects), but if you're looking for more control please consider the Create Issue Branch App/Action.

0 replies

✔ fixed

Default branch name should include numbers from issue title

Default branch name is currently in format of issuenum-words-from-issue-title e.g. 123-client-fix-broken-grapple

But in this example, the original issue title is Client 12 fix broken grapple. the devs are now always editing the branch name to add the client number.

The branch name they want is 123-client-12-fix-broken-grapple

Can we get number as allowed character in default branch name please?

We have the same problem with both client numbers and report numbers being omitted.

2 replies
@BellettiR

default branch name should be customizable! let's try not to make the same mistake as in gitlab ce :)

@Bestra

Can we get number as allowed character in default branch name please?

@700software we just deployed a fix for that this morning, thanks for bringing it up!

It would be great to see what's the branch you are branching off.
To double check it, right now, I have to click on Change branch source.

2 replies
@700software

Yeah, our team has made that mistake a few times- it's not obvious which branch it's based on, and two clicks to change instead of one.

@tdtm

Agreed. Important one IMHO.

Bug report with current behaviour:

Current:

  1. create an issue
  2. create a branch (feature/1-myissue)
  3. attach PR and close issue
  4. delete branch on remote through PR UI
  5. reopen issue
  6. try to create the branch from the UI again
  7. enter the same branch name as before (feature/1-myissue)
    Error: Sorry, the branch feature/1-myissue already exists.
    I've double checked the the branch does not exist on the remote.

Expected:
it should create a branch with the same name branched from the latest state of the repo.

5 replies
@Bestra

Thanks @chrisregnier! I can also confirm what you're seeing. The fix looks pretty straightforward. I think I can have something deployed in the next few days.

@Bestra

@chrisregnier I wanted to double check, when you say "attach PR and close issue" on step 3, can you go into more detail there as to the specific steps you're taking? For whatever reason I can't reproduce this today based on the steps above 🙇 .

Another point: Once you've attached your PR in step 3, I'd expect that in the Issue sidebar you shouldn't still see the linked branch feature/1-myissue in the Development menu, only your PR. Is that the case? Thanks again!

@chrisregnier

I would normally create a PR and link it with the issue. When PR gets merged it closes the issue, then I click the delete branch button on the PR. And you're correct, at this point, on the issue page I can see the linked PR in the Development section.
However, I'd swear that last week I could click on the Development gear and at the bottom was a link to create a new branch again. That doesn't seem to be there today, and I can't create a new branch from a reopened issue with an old PR now.

So maybe instead of giving a bug report here let me change this to expected behaviour:

  • From the issue I'd like to have the Development section always give me the option of creating a new branch from latest or a tag.
    This solves the following:
    • If I want a second branch with a diff name/pattern, even with another existing branch, it's possible to create it (it will fail if a branch with the same name exists obv)
    • If I reopen the issue, I should be able to create another branch from latest to start working on new fixes.
    • If I reopen the issue, I should be able to create another branch from a previous tag to start working on the hotfix

Thanks for looking into things!

very good very nice <3

0 replies

I'd like it to autoassign the issue to the branch creator if it currently had no assignee. I'm creating the branch meaning that i'm taking responsibility for that issue..... Some companies pre-assign issues, mine works on a self-service/assign-when-you-are-working-on-it basis.

2 replies
@700software

👆🏻 Great idea! Some of our developers forget to self-assign on occaision.

@700software

Would be great if there was an action in GitHub Projects Beta to change status from Ready To Start to In Progress actually.

Brilliant! Was just looking at my Git workflow and wondered if this was a thing, and it – now – is! 🎉

A couple of requests:

  • add option to pad numbers (I generally use nnnn-name)
  • optionally add a pattern (for those who like feature/<id>/<name>
  • automatically replace spaces with dashes when you type in the input field

Last one, something like this (which I may throw into a Chrome extension at some point):

let input = document.getElementById('branch-name')

input.value = input.value.replace(/^\d+/, s => {
  while (s.length < 4) {
    s = '0' + s
  }
  return s
})

input.addEventListener('input', e => {
  // variables
  const input = e.target
  const value = input.value
  const index = input.selectionStart

  // update
  input.value = value
    .replace(/[- ]+/g, '-')
    .replace(/^-|-$/g, '')

  // fix cursor
  input.setSelectionRange(index, index - (value.length - input.value.length))
})
0 replies

One simple thing that can be added is the branch title template

1 reply
@DewZ89

Would be really appreciated !

any example using API?

Thx

0 replies

I created a branch for an issue, even post deletion of this branch, I'm unable to create a new branch likewise.

1 reply
@Bestra

Hmm, @DeepaPatel-max I can take a look if you give me the repo url and the name of the branch.

Thanks for this cool addition!

However, I'm part of an organization where we all work in our own forks instead of the production repo.

Currently, the "Repository destination" selector is quite useless, cause it always selects the main repo instead of the fork by default. It would be cool if it could remember the last selection. Furthermore, the selector shows many unrelated repositories but not my own fork. So even if remembering the last selection is considered a bad idea, a fork of the repo should always be shown on top of the selection list.

1 reply
@fm-sys

Another thing: If I select my fork in the selector, the branch will be based on my forks master branch, not the master branch of the upstream repository...

Would LOVE if an option was open in GitHub Codespace that then launched the codespace setup step

image

1 reply
@odil-io

In extension to this, I would like to see the ability of configuring one of those options to be the default.

I was very surprised that this new workflow closed my issue when I merged a related PR. This wasn't happening before.

Compare the "old" workflow:

  1. Create a branch locally, e.g., 123-some-issue
  2. Push it to GitHub
  3. Create a PR
  4. Merge PR
  5. Issue 123 stays open

The new workflow:

  1. Create a branch via GitHub's UI
  2. Checkout locally, push commits to GitHub
  3. Create a PR
  4. Merge PR
  5. Issue 123 is auto-closed

(Note: In neither case I used the "closing keywords" in a PR description.)

Auto-closing is often undesirable for us, for example, we have issues that require multiple PRs to be merged first, or sometimes more manual work is needed after a PR is merged.

Fundamentally, I think that merely linking issues and PRs shouldn't be such a strong relation that merging a PR would close the issue. What I think would be better behavior:

  • Issue and PR can be "just linked" in which case I can see the PR in issue's sidebar and the issue in PR's sidebar. This is useful for navigation etc. but merging a PR wouldn't close the issue.
  • PR uses one of the closing keywords like fixes or resolves – in that case the issue is both visible in the sidebar and merging the PR closes the issue.

GitHub's UI itself is a bit vague, for example, for issues with linked PRs, the UI says "merging PR #123 may close this issue" – as if GitHub itself wasn't sure what's going to happen.

1 reply
@matthewferry

Would be neat if the sidebar linked items had an interaction where you could set it to "close on merge" or not. And maybe something in a .github issues config to change the default behavior if you want to override the default "close on merge" behavior.

Checking out a PR or cloning a repository has an option to use the gh command line tool. It would be nice if it was an option here too

CleanShot 2022-05-23 at 14 00 50

CleanShot 2022-05-23 at 14 03 45

0 replies

Now we can create branches directly from with projects page, that is great. Small but annoying issue - "Branch source" dropdown search is not working.

Steps to reproduce -

  1. Create an issue in projects
  2. Click on the project card, a panel will open on right with details
  3. Scroll down and select "Create a branch"
  4. A modal will open, click "Change branch source"
  5. In "Branch source" dropdown, search for a branch name

Result - Search does not filter out the branch

Expectation - Search should filter out the branch

Screenshot (810)

1 reply
@Bestra

Thanks @tusharlock10! I've made an issue for us to track this.

Lately this has been popping up, when creating branch into different project than originating issue. It used to work for same repository earlier, and it definitely contains files in master branch.

image

This also sometimes work when doing it like 10 times in a row.

0 replies

I just stumbled upon this feature after having created and pushed a bugfix branch; it would be nice if there was also a way to link an existing branch.

0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Issues
Labels
🆕 ANNOUNCEMENT Issues