Git
An indispensable tool for doing software development these days. This website is managed via Markdown files committed to a git repo (and then compiled in to a website using Hugo). Nearly all development these days which doesn’t use large media files uses Git by default.
Shout out to OhShitGit.com which is an excellent and memorable resource for fixing mistakes in git.
Undo last commit and keep changes Link to heading
git reset HEAD~ --soft
Fix committing to main instead of feature branch Link to heading
We basically branch from our existing main
(or master
) and then remove the extra commit.
git branch new-branch-name
git reset HEAD~ --hard
git checkout new-branch-name
...
Prune PR/MR branches Link to heading
Just run
git fetch --prune origin
Or if you are offline/dont-want-to-fetch
git remote prune origin
If you want this to always happen when you fetch you can run this to tell git to do it all the time
git config --global fetch.prune true
Reflog Link to heading
Shows a list of all the operations you’ve done in git indexed so you can reset your state.
git reflog
...
git reset HEAD@{$INDEX}
$INDEX
is the number of the change you want to switch to. Normally whatever happened right before things were messed up.