This page is part of my digital garden.

This page might be unfinished or have typos. These pages are meant as part of a public living notebook to be edited over time. For more, visit the page explaining the concept of a digitial garden.

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

git reset HEAD~ --soft

Fix committing to main instead of feature branch

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

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

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.

Last updated on