Let's say I have a branch named feature/1
. And also issue #1. I want to link that branch to that issue.
Is there a way to link that branch to that issue from the issue? Without making a commit.
Let's say I have a branch named feature/1
. And also issue #1. I want to link that branch to that issue.
Is there a way to link that branch to that issue from the issue? Without making a commit.
Directly from GitHub:
References
Certain references are auto-linked:
- SHA: be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd2
- User@SHA ref: mojombo@be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd2
- User/Project@SHA: mojombo/god@be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd2
- #Num: #1
- User/#Num: mojombo#1
- User/Project#Num: mojombo/god#1
It seems that directly (as in user/repo/branch) is not possible, but maybe by using the id of the tree?
As mentioned in another answer, GitHub automatically makes links to various things, including other GH repositories, but not to branches within those repositories. When I want to do this, I manually make the link like this:
[a link to a branch](/_user_/_project_/tree/_branch_)
Where _user_
, _project_
, and _branch_
should be replaced with the parts of the branch's URL. For example, a branch in GitHub's "linguist" project:
[api-changes branch in github/linguist](/github/linguist/tree/api-changes)
Important:
/
", also as in this example), then it will be relative to the root of the server of the current page's URL. Otherwise, paths that don't begin with slash will be treated as relative to the parent of the current page's URL. (This is basic HTML link specification.)tree
part of the URL when referring to specific branches of projects.Since Sept. 2022, you can link a branch from an issue.
Nov. 2022, since gh 2.19.0 and the gh issue develop
command:
$ gh issue develop 123 --name "my-branch" --base my-feature # create a branch for issue 123 based on the my-feature branch
$ gh issue develop 123 --checkout # fetch and checkout the branch for issue 123 after creating it
$ gh issue develop --list 123 # list branches for issue 123
$ gh issue develop --list --issue-repo "github/cli" 123 # list branches for issue 123 in repo "github/cli"
$ gh issue develop --list https://github.com/github/cli/issues/123 # list branches for issue 123 in repo "github/cli"
But, as noted by NotX in the comments (in Dec. 2022):
The new linking feature won't work for branches in other repos though.
So if you have a dedicated issues repo holding the issues from all the other repos, you've still go via mentioning.
But, as noted by L0tad in the comments, this is again true in July 2023:
Issues can be linked to branches from other repos.
I just did so myself for this exact use case, where the issue was located in a dedicated issues repo, and development took place elsewhere.
Note that from April 2013 ("Branch and Tag Labels For Commit Pages"):
If the commit is not on the default branch, the indicator will show the branches which contain the commit. If the commit is part of an unmerged pull request, a link will be shown.
That means referencing a commit from the issue will allow the user to see the branch (by looking at the commit), and even to see a link back to the issue (still by looking at the commit).
You can't reference the branch directly.
But you can make a reference to a branch compared to another branch. If you enter this:
https://github.com/user1/repo/compare/branch1...branch2
it will render as
branch1...branch2
Also, you can compare branches across forks. If user2
has forked repo
, this works:
https://github.com/user1/repo/compare/branch1...user2:branch2
Probably the easiest way is the create the issue first and create the branch in Github.
There is a "Development" section in the issue details, where you can create it automatically with a proper naming or link an existing branch.
I was looking for the same possibility in Git, but nothing was available so I decided to directly refer the brach with a markdown link by using the Hash reference.
# Issue02
## Commit Hash _<hash_number>_
...Rest of comments in the issue...
So, now in my organization we always do that reference when opening or closing an issue. It must be refered to a certain Hash and indirectly it is refered to the corresponding branch.
I guess you already now, but if not, to get the hash you will use git log
Note: It is not referencing to a certaing branch but a commit,
With some hours of work I think it is possible to automatically do this and create a command line tool,