Tag: issues

How to automatically close Issue(s) when you push a commit to GitHub – 046

You might have discovered this feature accidentally if you’ve ever pushed a fix up to GitHub using the magic words in your commit message. The story goes: You’ve committed a fix and pushed it to GitHub. Next you go to the Issue to close it, but to your (pleasant) surprise, the issue is already closed! How did it know?

I put pleasant in parenthesis because I hate technological surprises. I mean surprises are good, but I want to know what caused the surprise, so I’ll know how to surprise myself again in the future!

Two things must be true for your commit message to close an issue (see GitHub help article)

  1. contains a deviation of the words fix, close, or resolve, immediately followed by #<issue-number>
  2. the commit is on the default* branch (which is master by default, unless you or a repo maintainer has changed it)

If you take away nothing else from this tip, take away this: do not try to use the word Issue, e.g. Fix Issue #3 Otherwise, it won’t work. Gets me every time.

For example #1, suppose you have a repo where you want to delete a file that isn’t being used. You or someone else has created an Issue to track this work.

Delete Class1.cs #3 issue on github

You’ve fired up Visual Studio**, deleted the file from solution explorer (and saved the .csproj so the reference to the file is gone), and opened up the Team Explorer – Changes window to commit the change. You can type in “Fix #3” as the commit message to close Issue #3 in your repo.

commit message: Fix #3

Now when you return to your Issue, you’ll see it has been automatically closed with references to the commit automatically added to the Issue timeline.

Delete Class1.cs showing as Closed with how closed messages added to timeline

Now let’s say you are like me and after years and years and years of habit (and we’re talking about habit since the good ol’ days of RAID – where my MSFTies at!?!?), you put the word Issue in between the Fix and the #3. The Issue won’t get closed and you’ll have to close it manually.


And yes, as this blog post title implies, you can close multiple Issues.

For non-VS users out there, let’s do a command line example. Let’s say you have two Issues out there on your repo on GitHub. I’ll use close this time***, but close(s|d), fix(es|ed), or resolve(s|d) will all work.

git commit -am "Close #4 and Close #5"

*We’ll talk more about default branches later, but if you want to confirm the default branch, go to the branches link above the language bar in your repo.
**As if I could keep myself from blogging re Visual Studio Smile This is a Windows-first, non-Windows friendly blog, meaning I’m doing everything this from a Windows point of view. At some point the series will contain lots of Windows-only tips, but for now, I’m trying to straight the right balance in being non-Windows friendly.
*** In the command prompt example, I edited a readme file. I’m using the shortcut -am to do both the git add and the git commit at same time. More on these shortcuts later!

How to have pull requests added to an Issue’s timeline – 045

You might have noticed that when you create a pull request that refers to an issue, you’ll get an autocomplete dropdown.

Issue autocomplete when editing a pull request

If you just type in the item number, e.g. #3 (no issue title needed), or click on the desired Issue from the list, you’ll see in the preview that the #3 is automatically hyperlinked. Hovering over the hyperlink shows the Issue title as the tooltip.

#3 showing the title of the issue as the tooltip

After you’ve saved your edits (or created the pull request), go over to the Issue in question and you’ll see the pull request added to the Issue’s timeline.

Pull request added to the Issue's timeline

How to paste an image directly into an Issue on GitHub – 032

If you don’t know today’s tip, be prepared for a life-changing event (provided you are using Chrome).

Suppose you want to open an Issue on a project on GitHub. For example, let’s say you were learning Electron and tried out my your-moment-of-github-zen app on a Windows machine. You’ll quickly noticed that I wrote it on a Mac environment.

App appears offscreen on Windows

First, you can go to the repo, click on the Issue tab, (search to make sure there are no duplicate issues), and then fill out steps to reproduce the issue.

Place the cursor where you want the new image to go, and press Ctrl-v (or your non-Windows equivalent of paste).

Creating a new issue in repo

Not only will you see that the file was uploaded to GitHub, but also the Ctrl-v shortcut generated the markdown for showing images.

image uploaded and markdown generated

To make sure the image is :+1: click on the Issue – Preview tab.

image appears in preview

If you are not using Chrome, you’ll only see two options listed at the bottom of an Issue comment field.

pasting images not supporting in non-Chrome browsers

meaning you’ll have to save the file locally and then drag and drop it into the comment box (or use the Open File Dialog from the selecting them link).