How do you attach a new pull request to an existing issue on github?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
On GitHub, you do not "attach" a pull request to an issue through a separate binding step. The usual workflow is to reference the issue from the pull request title, description, or commits so GitHub creates the relationship and, if you use a closing keyword, closes the issue automatically when the pull request is merged.
The Simple Way: Reference the Issue Number
If the issue is #42, mention that number in the pull request body:
Other common keywords include:
These phrases do two different jobs:
- a plain reference such as
#42links the pull request and issue in the UI - a closing phrase such as
Fixes #42tells GitHub to close the issue when the pull request is merged
If you only want a visible relationship and do not want automatic closure, use a neutral phrase like Related to #42.
Typical Command-Line Workflow
Create a branch, make the change, push it, and open the pull request:
Then open the pull request on GitHub and include the issue reference in the description:
Once the pull request is created, the issue page will show that it is linked from an open pull request. After merge, GitHub closes the issue automatically if you used a closing keyword.
Referencing from the Commit Message
GitHub also understands issue references in commit messages. For example:
That can work well for small repositories, but many teams prefer to put the closing keyword in the pull request description instead. The pull request body is easier to edit, easier for reviewers to see, and less likely to be lost in a squash-merge workflow with rewritten commit messages.
Linking Without Auto-Closing
Sometimes a pull request only completes part of the work. In that case, do not use Fixes, Closes, or Resolves. Use a neutral reference:
This preserves traceability without prematurely closing the issue.
That distinction matters in larger projects where one issue may require several pull requests across refactoring, tests, and rollout work.
Cross-Repository References
If the issue lives in another repository, use the full reference format:
This reliably creates a visible cross-reference. Automatic closure behavior can depend on repository relationship and permissions, so when you are working across repositories, treat the cross-reference as the safe baseline and verify whether auto-closing is appropriate for your setup.
What Reviewers See
When the reference is recognized, GitHub surfaces it in several places:
- the issue timeline shows that a pull request references the issue
- the pull request sidebar may display linked development items
- merging the pull request can close the issue automatically if a closing keyword was used
That shared history is the real value. Reviewers can move from the code change to the original bug report or feature discussion without guesswork.
Good Pull Request Hygiene
Issue linking works best when the pull request description explains the relationship clearly. Do not drop Fixes #42 into an otherwise empty PR body. Add context:
- what changed
- why the change solves the issue
- what was tested
Example:
That gives the issue tracker a clean audit trail and gives reviewers enough information to evaluate the patch.
Common Pitfalls
- Mentioning the issue number only in a comment after the pull request is opened. Put the reference in the PR body or commit so GitHub treats it as linked development.
- Using
Fixes #42when the pull request only solves part of the issue. Use a neutral reference if the issue should stay open. - Forgetting to include the repository name for cross-repo references. Use
owner/repo#numberwhen the issue is not in the current repository. - Relying only on the issue title or branch name to imply linkage. GitHub needs an explicit reference to connect the records.
- Hiding the issue reference inside a noisy or unclear pull request description. Keep the relationship obvious so humans and tooling can both read it correctly.
Summary
- Link a pull request to an issue by referencing the issue number in the PR body or commit.
- Use
Fixes #123,Closes #123, orResolves #123for automatic closure on merge. - Use neutral phrases such as
Related to #123when the issue should remain open. - Cross-repository references should use the full
owner/repo#numberform. - A clear PR description makes the issue link useful to both reviewers and future maintainers.
Related reading
- How do you change the capitalization of filenames in Git?
- How do you copy and paste into Git Bash
- How do you fix a bad merge, and replay your good commits onto a fixed merge?
- How do you get git to always pull from a specific branch?
- How do you merge two Git repositories?
- How do you organise multiple git repositories, so that all of them are backed up together?
- How do you push a tag to a remote repository using Git?
- how do you push only some of your local git commits?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseNo course covers this one yet
Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.
Build my courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.