Shift Gear with Git
Git is an extremely powerful VCS, with lots of handy functions. Standard commands like add
, commit
, checkout
, etc. are enough to accomplish your job. But, in complex repositories with several branches developed in parallel, more sophisticated commands can make you save a lot of time.
In this post I will describe a couple of them. But first I want to start with a smart hack that I've been using for several years with great satisfaction.
Customize Your Prompt
One of the most common operations is to check if everything has been committed; git status
does the job and also tells you the active branch. However it is quite boring to type the command every time.
Some years ago I've found a site that proposed an handy solution: run git status
in background and customize the prompt according to the result. The original webpage is no longer active, but luckily someone saved the script to GitHub.
You can copy the content of the script in one of your startup files (such as .bash_aliases
) and you are done. The name of the active branch will always be visible and the color green or red will tell you whether the working tree is clean or there are still uncommitted changes.
Show More Information on Branches
How many times have you used git branch
to list all the branches in your local repository? Most of the times the name is not enough. Maybe you want to know if in some of them there are non-pushed commits or modifications not yet pulled.
To help you, the branch command provides two levels of verbosity (but I always use the second). With git branch -vv
, you have the complete situation of your local repository under control.
Use Worktrees
When I wrote this post about git stash
, git worktree
had not been introduced to Git yet. In few words, worktrees give you the possibility to checkout multiple branches from the same repository in separate directories. The following article explains very well why worktrees are so powerful.
The best part of worktrees is that, git branch -vv
will give you also this information and the directory where it has been checked out.
Additional Resources
Image from Pixabay by Jarkko Mänty licensed under the Pixabay License.