Git Tips

General

  • Favor smaller, atomic commits
  • If needed, fixup history before pushing
    • git rebase -i
    • git commit --amend --no-edit, optionally --reset-author to reset date

Aliases

This is a useful visualization I use all the time:

alias.lg=log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%C(bold)%d%Creset %s %C(brightgreen)(%cr) %C(cyan)<%an>%Creset' --abbrev-commit --branches

This is niche but potentially interesting:

alias.sizeof=ls-tree -r -l HEAD --

Scenarios

In the event you have commits on main which should be a topic branch

  • git switch -c topic
  • git switch -C main origin\main
    • Or, if you also want to be up to date, you could do git fetch origin main:main and then git rebase main

In the event you determined you had the wrong value of core.autocrlf, changed it, and need to apply the change to all files

  • Make sure there are no important uncommited changes
    • If there are, maybe use git add --renormalize
  • git read-tree --empty
  • git reset --hard