Git worktree and nifty shell commands

Managing my work using Git worktree, using pushd and popd to navigate directories, and the usual cool stuff I've found around the web!

Hiya!

Welcome to another issue of One More Line. Where I share tips on getting a little better at coding, writing, or design - one line at a time.

I’m continuing the Git theme this week with git worktree. As well as sharing two shell commands I found.

Git worktree to manage work

I’ve been looking for an alternative to git stash. In most cases, it’s fine. But it gets dicey if I stash pop and there’s merge conflicts in multiple untracked files.

Enter: git worktree.

Basically, git worktree copies your project in another directory. You treat that directory like another branch. Where you "switch" between branches by changing directories.

Let’s say I’m working on a large prototype but I need to make a quick bug fix. Instead of Git stashing, switching, pushing, switching, popping. I would create a new Git worktree, change directories, push, change directories. Seems neater.

Here's the a lightly altered example from the Git scm docs

$ git worktree add -b emergency-fix ../temp master
$ pushd ../temp
# ... Open folder in editor - hack hack hack ...
$ git commit -a -m 'emergency fix for boss'
$ git push
$ popd
$ git worktree remove ../temp

The git worktree commands deal with the setup and teardown of the temp folder. You treat that folder like the main project. Opening it up in a code editor, making changes, and pushing.

What’s also interesting is the two shell commands I’ve never seen before.

Pushing and popping directories

As we navigate directories, our shell keeps the history in a stack. The dirs command will show you that history.

pushd will push a directory onto that stack, changing directories to the specified folder.

popd will pop a directory off the stack, sending us back to the previous directory we were in.

Basically, we can navigate to one directory using pushd and switch back to the previous directory using popd.

Conclusion

I wonder if git worktree would be too slow with our large monolith at work. I’m very curious to try it. But I’m really glad I researched it. because I found popd and pushd. Two nifty shell commands I can’t wait to use more often.

Cool stuff around the web

James Hoffman was on Matt D'Avella's podcast: Three Rules. Hoffman has thoughts on external validation (around 16:30). What if you couldn't tell anyone about the thing you did? Would you still do it? I’d like to answer yes for most of the things I do. But the allure of external validation is strong.

Elliot Jay Stocks' book: Universal Principles of Typography is a stunning book chock full of information about typography. I picked it up over the weekend and I highly recommend!

Active vs Passive voice by Michael Lynch goes through some scenarios where passive voice might be more appropriate then active. I just assumed active voice is always better.

Thanks for reading this week's newsletter. If you have any thoughts or questions, feel free to reach out by replying to this email or send me a DM on Bluesky.

Catch you next week!

Jono