Using GitHub Conventions in Commit Messages

You can enhance your commit messages with GitHub-specific features, such as emojis, issue references, and coauthor credits.

1. Emojis

Emojis are little images or icons that convey an emotion or concept. Widely used on GitHub.com, emojis can bring a bit of levity and whimsy to an otherwise seri­ous occupation.

In the commit summary box, you can initiate the emoji picker by typing the : character. If you keep typing, you can list all emojis that start with the letters you type. For example, Figure 7-8 lists all emojis that start with ar as the result of typing :ar.

You can select the one you want with the arrow keys and then press Tab to com­plete it. Desktop then fills in the full text of the emoji, which in this case is :art:.

2. Issue references

GitHub also lets you reference an issue in a commit message with the format #123 where 123 is the issue number. Desktop has support for looking up an issue when writing a commit message. To try this out, create an issue ahead of time so that you can reference the issue in a commit message. As an example, we created an issue that describes the need to replace the alert message with a better approach. We reference that issue in this commit message.

  1. In the commit description field, type Fixes #.

A few recent issues appear. If you don’t see the issue you want to reference and you don’t remember the issue number, You can start typing a word that’s in the issue that you remember. For example, when we type #alert a couple of issues pop up (see Figure 7-9).

 

  1. Select the issue you want to reference and press Tab.

In this example, we select issue 4. Desktop replaces #alert with #4.

3. Giving credit to coauthors

Git doesn’t support multiple authors directly. However, the Git community cre­ated a convention for specifying multiple coauthors in a commit that is now sup­ported by GitHub.

To give credit to coauthors:

  1. With the Desktop open, in the commit box with the Description label, click the little icon with a person and a plus sign in the bottom left corner.

Desktop adds a textbox to enter a coauthor’s GitHub username.

  1. Click the @ symbol to see a list of potential users, as shown in Figure 7-10.

GitHub lists only users who have access to the repository — for example, collaborators and org members (if the repository belongs to an organization).

Just like the issue selector, you can also search by first name, last name, or username by appending a bit after the @. For example, if I only remember y coauthor’s last name, I could type @guth to find my coauthor. Press Tab, and Desktop replaces whatever you typed so far with the selected user’s full username.

  1. To create the commit, click the Commit to master button.

To see your commit, click the History tab and click the you just created (see Figure 7-11).

You can see in the commit message in the right pane that Sarah’s username was replaced by the line

Co-Authored-By: Sarah Guthals <sarah-wecan@users.noreply.github.com>

That’s the actual convention for specifying coauthors in Git commit messages. By using Desktop, you don’t have to remember the exact format. You can just specify a username and let Desktop handle the rest.

Source: Guthals Sarah, Haack Phil (2019), GitHub for Dummies, Wiley.

Leave a Reply

Your email address will not be published. Required fields are marked *