being Pro in git?

Mon Feb 15 2021

from Develop and assuming your master is up to date with origin/master

git reset --hard master

Wip & UnWip

Sometimes I’m working on a branch and I won’t finish what I’m working on for some reason. Maybe there’s a more urgent thing that needs to be done, or I’m just messing around and looking at different ways to solve a problem, and I want to abandon this and work on something else.

In this case I want to stash my changes, for a long period of time, and I want to attach them to a specific branch.

I’ve been using a solution that works really well for my workflow:

; ~/.gitconfig

[alias]
  wip = !"git add .; git commit -nm 'WIP: This is a work in progress commit'"
  unwip = !"if git log -1 --pretty=%B | grep 'WIP'; then git reset HEAD~1; else echo 'No WIP commit was found'; fi"

Simply do git wip to add all your changes to branch under a WIP commit.

To revert, do git unwip, which has a safeguard to prevent you from accidentally unwipping normal commits.

Better log

The default git log is usually too verbose and long for my workflow. In most situations I just want to see the latest 10 commits with each commit on one line of output.

The following alias will just do that:

; ~/.gitconfig

[alias]
  slog = "!f() {             git log               -${1-10}               --graph               --abbrev-commit               --decorate               --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(auto)%d%C(reset)';           }; f"