How to close issue via PR whose target is not the default branch

Solution 1:

As the answer of this question says, an Issue will only close if it's merged into the main branch. There is no such option to do what you said in your question.

the referenced issue will automatically be closed when the PR is merged into the default branch

That's why in 4 years nobody could tell you how to do this.
I think that your question it's useful because such option should be available for cases like your one.


The only way right now is to do it manually.

  1. Merge the Pull Request
  2. Close the issue with the close button

But you could build an github action that does this automatically:

name: AutoIssue

on: # This you can set it up as you want, I made it trigger on a commit
  push:
    branches: [ master ]

  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - name: Merge Pull Request
      uses: juliangruber/merge-pull-request-action@v1
      with:
        github-token: ${{ secrets.GITHUB_TOKEN }}
        number: <NUM> # Enter here the pull request number you want to merge
        method: squash
    - name: Close Issue
      uses: peter-evans/close-issue@v1
      with:
        issue-number: <NUM> # Enter here the issue number you want close
        comment: Auto-closing issue

The only things you have to change are the <NUM> placeholders