Developer Hacks – Modern Command Line Tools and Advanced Git Commands
Working with the terminal and with Git are among the basic techniques for developers. This article presents a modern development setup, state-of-the-art alternatives to classic shell programs, and advanced git commands. Using these tools will help you navigate your projects with greater ease and speed, allowing you to focus on what truly matters: building great software.
For Mac users, iTerm2 offers more features than the default Mac terminal app: split panes, hotkey windows, and extensive configurability. Personally, I use it with the Catppuccin Macchiato color theme and especially like its feature of having a scratchpad terminal quickly available via hotkey:
To further enhance productivity, consider using Rectangle for window management, Alt-Tab for window switching and Maccy for clipboard history.
Zsh, one of the most popular shells and the default on Mac, can be customized with oh-my-zsh, a framework that simplifies the management of zsh configurations. It is often used with the powerlevel10k prompt for an aesthetically pleasing and informative terminal prompt. Additionally, you can enhance your zsh experience with plugins like zsh-autosuggestions or zsh-syntax-highlighting.
Newer, but less common shells are nushell, fish, and xonsh. To me, xonsh looks particularly interesting as it allows mixing both Python and shell commands.
For many of the classic commands like ls, cat, find etc., there exist modern alternatives. Compared to their traditional counterparts, those modern shell commands are often faster (as they are often written in Rust), more colorful and more convenient, e.g. by respecting gitignore files.
eza and lsd both provide a better file listing with color highlighting, icons, and additional configurability.
As text file viewer, bat uses line numbers, syntax highlighting and git changes. It uses paging for longer output (scroll text like with less), but defaults to plain printing when used for piping.
For showing file and folder sizes, dust provides a better sorted and visualized output than the classic du:
fd is a modern alternative to find to search for files, much much faster and with cleaner syntax: fd PATTERN instead of find -iname '*PATTERN*'.
A tool for searching text in files. Using sensible default, ripgrep considers gitignore rules and ignores hidden and binary files. Several times faster than the original grep.
For the classic htop tool to check system status, modern alternatives are for example bottom, glances or btop (there exist even more). Although they largely use the same system metrics, they differ in their customizability and how the display and visualize data:
fzf searches text with a so-called fuzzy search: It will also find slightly different spellings, with characters omitted. Text files, shell history or the output of other commands.The fzf-zsh-plugin lets you automatically search your history with fzf when you type ^R.
Apart from everyday’s commands – git init, clone, git pull, add, commit, git push, diff or show – there exist some git features which can make your life considerably easier in many situations. Let me give a git commands overview of these helpful features.
A few helpful options are (set with git config –global):
Git’s interactive rebase can be used edit commit history by merging commits, editing their messages or dropping some of them. This is convenient when e.g. cleaning up a feature branch before merging. git rebase -i opens a lists of commits in an editor where you can change the default “pick” to whatever command fits. See a detailed description here.
Imagine the following scenario: Your code is not working properly, but you can’t figure out what’s wrong. You just know that a week ago, everything ran fine.
Git bisect can help you pinpoint the exact commit a bug was introduced. You run git bisect start, mark the good and bad commits (with git bisect good / git bisct bad <hash>). Git will automatically switch to the commit in the middle. You can mark it as good or bad and then git will switch again to commit in the middle between the good and bad commit, repeating this process until the guilty commit was found.
Accidentally deleted a branch or lost a commit? Don’t worry, these are still in git! You can use git reflog to get a list of previous commits/branches you were on and find the hash of the deleted object (and then use git checkout to).
Let's say you're working on a feature, and you have many edited or new files. Suddenly, you have to fix a commit on the main branch. You’d typically either commit and stash your changes and switch to main or create another copy of the entire repository somewhere else to have a clean state.
With git worktree, you can create another worktree, something like “a copy of the repo inside your repo”, which you can delete after making changes:
git worktree add ./fix-critical-bug main
# go to the fix-critical-bug directory, commit and push solution on the main branch
git worktree remove ./fix-critical-bug
# return to working on your feature
In conclusion, by integrating these modern command line tools and advanced Git commands into your workflow, you can enhance your productivity and focus on crafting software that creates real business value.
Want to become part of the team?
Comment editer by attacke
We have received your feedback.