21

I spend my day doing this:

  1. Read an issue on a Gitlab-powered issue tracker,
  2. Fix the issue,
  3. Commit and push to the same Gitlab-powered Git server,
  4. Mark the issue as closed.

To remove the 4th step, how can I close the issue automatically when committing?

Nicolas Raoul
  • 58,567
  • 58
  • 222
  • 373

2 Answers2

29

Commit and push using this syntax:

git commit -m "Sort more efficiently" -m "Closes #843"
git push

This will commit and close the issue.
Note that unlike Github a single -m will not work.
The following will appear on the issue page:

enter image description here

References:

ifnotak
  • 4,147
  • 3
  • 22
  • 36
Nicolas Raoul
  • 58,567
  • 58
  • 222
  • 373
  • 1
    How do you close an issue on a subgroup, called e.g. backlog? `git commit -m "Sort more efficiently" -m "Closes backlog#843"` – KargWare Dec 02 '20 at 08:22
  • 1
    Looking at the documentation, it says this only works on the default branch. Is there any way to have this work on, for example, the `develop` branch? – Alex O'Connor May 31 '22 at 20:23
  • Very interesting that one cannot do both. Quite counterintuitive. I am looking forward to a change in this behaviour since many people either come from GitHub or work in parallel with both GitHub and GitLab. – rbaleksandar Jun 03 '22 at 15:26
11

According to this link from gitlab, you will be able to do that with a variety of words such as "fixes" or "closes". It does not need to be in a seperate line.

So you could have the following message:

Fixes #20. I had to replace "foo" with "bar".

And that will close issue #20.

ifnotak
  • 4,147
  • 3
  • 22
  • 36
thalacker
  • 2,389
  • 3
  • 23
  • 44