How do I reference an existing branch from an issue in 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?


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.

Note that from April 2013 ("Branch and Tag Labels For Commit Pages"):

  • Any commit can mention the branch it is part of:

branch part of commit

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.

Link to pull request

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