GitHub and GitLab commands cheatsheet


Both GitHub and GitLab provide shortcuts for interacting with the layers they have built on top of Git. These shortcuts are a convenient and clean way to interact with things like issues and PRs. For instance, using Fixes #2334 in a commit message will close issue #2334 automatically when the commit is applied to the main branch. However, the layers on top of Git differ between the two, and therefore the commands will differ as well. This document is a cheatsheet for issue closing commands; I plan to add more of these commands over time.

If this page contains outdated information, suggest a fix via GitHub.

  1. Get your branches again after a shallow clone
  2. Stashing changes
  3. Close an issue via a pull request title or commit message
    1. GitHub
    2. GitLab

Get your branches again after a shallow clone

For large repositories, it is often useful (or necessary even) to make a shallow clone. For example, when cloning your fork at someusername of the Rust language, you can use:

git clone --depth=1

However, now all branches are missing so you cannot continue working on your PRs. To fix this, use:

git remote set-branches origin '*'

git fetch -v --depth=1

git checkout the-pr-branch

Thanks to marlo and jthill on StackOverflow.

As a side note, sometimes it's useful to merge upstream into the PR branch from the GitHub web interface. To do this, browse to the branch inside the fork and click on "Sync fork". This will merge the upstream's main into the branch.

Stashing changes

For some reason, I've never been comfortable with temporarily stashing my changes away via Git stash. However, a very simple alternative is to just write the diff to a file via

git diff > mychanges.patch

At a later point, this file can be used to restore the changes via

git apply mychanges.patch

Close an issue via a pull request title or commit message


On GitHub use (docs):


Fix #2334
Fix octo-org/octo-repo#2334
Fix #2334, fix octo-org/octo-repo#2334


On GitLab use (docs):


Fixes #2334
Closes #2334
Closes #4, #6
Closes group/project#123