Technosorcery

Ramblings of Jacob Helwig.

Making Git a Little Less Verbose

| Comments

Git has some output that can be very helpful to people getting started with it. Once you’ve been using Git for a while, however, you may find that the advice that Git provides to help deal with certain situations just ends up taking up screen real estate. Fortunately, there is a way to turn off a number of these messages.

There are currently six settings to adjust the extra help messages that Git provides by default:

~/.gitconfig with all optional messages off
1
2
3
4
5
6
7
[advice]
  pushNonFastForward = false
  statusHints = false
  commitBeforeMerge = false
  resolveConflict = false
  implicitIdentity = false
  detachedHead = false

pushNonFastForward

pushNonFastForward will turn off the extra help output by git-push(1) when attempting to push a non-fast-forward without using -f, or the +<ref> form of a ref.

Above, we see the output of attempting to push a non-fast-forward, and below we see the output after setting advice.pushNonFastForward. The difference is only three lines, but the output feels a lot cleaner especially if you already know how to deal with non-fast-forward pushes (merging, or forcing as appropriate).

statusHints

statusHints will turn off the hints provided by git-status(1) to help work with changed & new files in the repository.

Again, we see the command output above with the advice setting left at the default of true. Below we can see that we save about four lines of output every time we run git status on the command-line.

commitBeforeMerge

commitBeforeMerge will turn off the reminder to commit, or stash your changes if you have uncommitted changes that conflict with what you are attempting to merge.

The difference with advice.commitBeforeMerge doesn’t save us any lines of output, but it does help visually distinguish the error message that includes the list of files, from the line telling us that Git is aborting our attempt to merge (shown below).

resolveConflict

resolveConflict affects multiple commands, all of which share the scenario of the command aborting due to unresolved conflicts in the work tree/staging-area. The example I will show below is trying to commit before marking all conflicts as resolved.

This is another setting that can save us a couple of lines of output that don’t really help us much after we’ve done this task a couple of times.

implicitIdentity

implicitIdentity is one that I don’t personally use since I have my name and email set in my ~/.gitconfig, but can come in handy if you rely on Git automatically guessing your name and email from the system you’re on.

The output after running git commit when Git guesses your name and email is…well…massive. If you rely on having an email generated from the FQDN of the current host, you really should turn off this advice, and save yourself a ton of wasted screen real estate.

detachedHead

detachedHead is quite handy if you’re comfortable working with Git in a ‘detached HEAD’ state (doubly so, if you have your shell prompt setup to help you remember if you’re currently in a detached head state or not.

Turning off the advice when entering a ‘detached HEAD’ state is another one that will end up saving huge amounts of screen real estate once you get comfortable working with this aspect of Git (especially if you have your prompt remind you)..

Have an idea for a post you'd like to see? Spot something that needs correcting? Feel free to contact me, or open an issue on the GitHub repository.

Comments