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.
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 https://github.com/someusername/rust
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.
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
To delete only one token, use
git credential-store erase
For example, to erase the token for https://github.com
, use
echo -e "protocol=https\nhost=github.com" | git credential-store erase
On GitHub use (docs):
close
closes
closed
fix
fixes
fixed
resolve
resolves
resolved
Examples
Fix #2334
Fix octo-org/octo-repo#2334
Fix #2334, fix octo-org/octo-repo#2334
On GitLab use (docs):
Close, Closes, Closed, Closing, close, closes, closed, closing
Fix, Fixes, Fixed, Fixing, fix, fixes, fixed, fixing
Resolve, Resolves, Resolved, Resolving, resolve, resolves, resolved, resolving
Implement, Implements, Implemented, Implementing, implement, implements, implemented, implementing
Examples
Fixes #2334
Closes #2334
Closes #4, #6
Closes group/project#123