How do I reference an existing branch from an issue in GitHub?
GithubGit BranchGithub Problem Overview
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.
Github Solutions
Solution 1 - Github
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?
Solution 2 - Github
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:
- GitHub's Markdown processor creates links using the exact URL value enclosed within parentheses. You must specify the URL considering how a browser would handle that link. If the URL specified is only the path portion (as in this example), browsers will treat the path as relative to the current page's URL. If that relative path begins with a slash ("
/
", 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.) - Do not forget to include the
tree
part of the URL when referring to specific branches of projects.
Solution 3 - Github
Note that from April 2013 ("Branch and Tag Labels For Commit Pages"):
- Any commit can mention the branch it is part of:
> 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).
Solution 4 - Github
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
Solution 5 - Github
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,