My Git cheatsheet
🇺🇸 – Friday, September 27th 2024
Keywords: #Git, #commits, #GitHub, #GPG, #CLI
A bit of context
Sometimes I need to get back some commands I used in my terminal so as to work on my Git repositories of GitHub / GitLab projects. But I can have often some doubts about them, so I decided to list here some useful commands as a cheatsheet or a simple reminder to keep and share. I will try to keep it updated. There are nice resources in the bottom of this document!
Applying some common Git configurations
Use also the —global option if you want to apply this configuration everwyhere.
Showing GPG keys to get ID to use for commits
Useful to remember the ID of the GPG key to use to sign commits. More details in this other publication (in french).
Verify GPG signature of commits
Keep in mind the software forges like GitHub and GitLab provide also some verification process for commits.
Display contributors of a commit
You can also filter to get other metadata in commits, find here for example some ideas.
Create branch from another and switch
That's not the only command of course, but I like this one.
Get rid of the last N commits
You can use of course other things instead of HEAD~N.
Reword, reorder or squash last N commits with interactive rebease
You can use of course other things instead of HEAD~N. Beware of fixup and squash, not the same uses with the commit messages.
Create a Git patch
Allows to generate a Git patch from a diff to apply or send it later.
Keeping somewhere changes temporary
Useful for drafts or temporary changes you don't want to version.
Find someone to blame (maybe you!)
The aim is to display who modified lines of files.
Clean the repository
Clean the project, get rid of files, but beware, you may loose things!
Work on a fork and submit
The workflow is simple: fork, create local develop branch with your dev stuff, make meaningful commits, then cherry-picks from this branch to a virgin one so as to submit a nice and simple pull request.
Resources
You have also some online resources like git-cheat-sheet.readthedocs.io.
But, maybe most important, you can refer also to this amazing comic of Julia Evans, available online and also buy her book. Her comic bellow is licensed under CC-BY-NC-SA 4.0.
[Code samples rendered with carbon.now.sh]
— Last update: Wednesday, October 23th 2024 —
Did you enjoy reading this blog? Give me a beer 🍺 or use something else ❤️‍🔥 Licensed under CC-BY-SA 4.0. Opinions are my own. To contact me, feel free to choose the most suitable medium for you, or for example Mastodon.