So You Think You Know Git


Hi friends!

“The nice thing about Git is that it’s very general. … There is a lot of stuff you can do with Git; it’s not just version control that it’s fun to play with.”

- Scott Chacon​, GitHub's co-founder

A recent talk with the same title as this email was given by Scott Chacon, founder of GitHub, to students earlier this year. I was so inspired by it that I watched it repeatedly and decided to summarize the tips and tricks I discovered—features I didn’t even know existed after a decade of using Git daily.

Git is getting close to 200 subcommands 🤯, here are some unknown yet super useful ones!


1. Conditional Configurations

Did you know you can set conditional configurations in Git? This allows you to use different settings for different projects. For instance, you can set a global email for most repositories and a specific email for work projects without changing settings manually every time. Just use a relative path in your config file and let Git handle the rest.

Here’s an example git config:

[include]

path = ~/foo.inc ; find "foo.inc" in your `$HOME` directory

; include if $GIT_DIR is /path/to/foo/.git

[includeIf "gitdir:/path/to/foo/.git"]

path = /path/to/foo.inc

2. Custom Aliases

Creating custom aliases can save you a lot of time. For example, you can alias the stash command to include untracked files:
git config --global alias.stasha 'stash --all'

Now, running `git stasha` will stash everything, including new untracked files.

3. Reuse Recorded Resolution (rerere)

Git’s rerere (reuse recorded resolution) feature can remember how you resolved conflicts and apply those resolutions automatically in the future. This is a hidden gem that saves time on recurring merge conflicts. Enable it with:


git config --global rerere.enabled true

4. Enhanced Blame and Log

Using git blame with the -w flag ignores whitespace changes, making it easier to see who made significant changes:

git blame -w <file>

Similarly, git log -S <expression> can search for specific expressions within your commit history. Add the -p flag to see the diffs:

git log -S <expression> -p

5. Code Movement Awareness

The git blame command with -C detects code movement within files. Running it twice (-C -C) or thrice (-C -C -C) can even track code movement across files:


git blame -C -C <file>

New Git Features!

Git continuously evolves, and here are some fresh additions:

  • Column View for Branches: Display branches in columns for better readability:


git branch --column

  • Sign Commits with SSH: Sign your commits using SSH keys instead of GPG:


git config --global gpg.format ssh
git config --global user.signingkey <your_public_ssh_key>`

  • Maintenance Tasks: Automate repository maintenance tasks to optimize performance:


git maintenance start git maintenance run --schedule=hourly

  • Safe Force Pushes: Avoid overwriting others’ changes with --force-with-lease:


git push --force-with-lease


That's it!

I hope you found it useful. Please reply with any feedback or questions.

Have a great weekend!

Whenever you’re ready, here’s how I can help you:

ESPRESSO FRIDAYS

Every once in a while I send hand picked things I've learned. Kind of like your filter to the tech internet. No spam, I promise!

Read more from ESPRESSO FRIDAYS

Hi friends, Tmux is a fantastic tool for managing terminal sessions, but it has its limitations. One major drawback is the lack of a floating pane feature, which can make navigating between different panes cumbersome and inefficient. Me frustrated with Tmux lack of floating panes while Zellij is killing it... Most users workaround this by creating new Tmux windows or panes, or by using hidden splits to zoom in and out. These methods work but can be inefficient and require many keystrokes,...

My Neovim takes roughly 113ms to fire up. THIS IS FAST. However, I don’t lazy load anything. Being a Lazy.nvim user, it’s kind of a shame I’m not actually making use of my plugin manager's flagship feature. But then again, it takes 113ms for nvim to start, what is there to gain here? Let’s say I drop it to 50ms. I gained 60ms which means that if I’m going to spend 30 minutes to actually reduce it, I’d have to open Neovim 15,929 times to get my time back 🤣. With an average of probably 5 times...

Hi Friends! Curious about Nix? Me too. The past few months of exploring it were quite interesting, to say the least. And it still feels like I've barely scratched the surface. [TL;DR] That said, it's already replacing some of my old workflows and I'm really happy discovering it, even while not even using Linux for most of my local work. What’s Nix? Nix is a powerful suite of tools, including a package manager (Nixpkgs), language (Nix DSL), and operating system (NixOS). It provides a robust...