GitHub logo on the screen smartphone and notebook closeup.
Image: prima91/Adobe Stock

Git is the most widely-used version control system on the market. It’s powerful, flexible and makes collaborating on development projects a snap, but one thing you may have come across is that you have to rerun certain config commands for each initialized repository.

SEE: Hiring kit: Python developer (TechRepublic Premium)

For example, you’ve initialized the directory PROJECT and then you’ll need to configure your username and email address with commands like this, run from within the PROJECT directory:

git config ""
git config "Jack Wallen"

Or, you could use the –global option, which, as the name implies, is global. These commands would look like this:

git config --global ""
git config --global "Jack Wallen"

The difference between the two is that the first set of commands is run on a project-by-project basis, whereas the second commands are used to set global configuration options. The latter option is more efficient because it ensures you don’t have to run those commands for every project you work with.

When using the –global option, it generates a configuration file within your HOME directory, named .gitconfig. That file is where you can set several important configuration options.

How to open the .gitconfig file

There are two ways to open the .gitconfig file. First, you can use the git command like so:

git config --global --edit

This will open your .gitconfig file in your default text editor.

You can also open the file directly with the command:

nano ~/.gitconfig

The contents of that file will look something like this:

        email =
        name = Jack Wallen

        spellcheck = false
        maxrecent = 6

        editor = gedit

        ui = auto

[filter "lfs"]
        required = true
        clean = git-lfs clean -- %f
        smudge = git-lfs smudge -- %f
        process = git-lfs filter-process

Let’s take a look at some of the handy additions you can make to this file.

The first addition to make is setting your default branch. Let’s say your default branch is main. To set that, you would add the following at the bottom:

        defaultBranch = main

Add that at the bottom, making sure you follow the same indentation as set in the file.

Next, let’s add your default text editor with:

        editor = nano

Let’s say you tend to work with certain repositories throughout the day and you don’t want to have to type out the addresses every time. You can create shortcuts in .gitconfig like so:

[url ""]
        insteadOf = gh:

[url ""]
        insteadOf = gist:

[url ""]
        insteadOf = bb:

You might also want to enable colored output. For example, you can set different colors for things like branch, diff, and status. Here’s an example:

        ui = true

[color "branch"]
        current = yellow reverse
        local = yellow
        remote = green

[color "diff"]
        meta = yellow bold
        frag = magenta bold
        old = red bold
        new = green bold

[color "status"]
        added = yellow
        changed = green
        untracked = red

You could also add aliases for commands, to make your work even more efficient. Aliases in the .gitconfig file look like this:

        # Show all branches
        br = branch -av 
        # Show the current branch name (useful for shell prompts) 
        brname = !git branch | grep "^*" | awk '{ print $2 }' 
        # Delete a branch brdel = branch -D

You can also set your default web browser like so:

        browser = firefox

Or maybe you need to use the Gmail outgoing server settings like so:

        smtpencryption = tls
        smtpserver =
        smtpuser = EMAIL
        smtppass = PASSWORD
        smtpserverport = 587

Where EMAIL is your Gmail address and PASSWORD is an app password you’ve created.

Finally, you can also set your Github credentials like so:

        user = USERNAME
        token = TOKEN

Where USERNAME is your GitHub username and TOKEN is an authentication token you’ve generated from within the GitHub security settings.

After adding your options, save and close the file. You can then view the contents of that file with the command:

git config --list --show-origin

You should not only see all of your entries but the path of the file that contains them, which will be file:/home/USER/.gitconfig, where USER is your username.

And that’s your introduction to the .gitconfig file. If you’ve ever wanted to get very specific about how Git is configured on your machine, you know have such power at your fingertips.

For more information on how to configure Git, make sure to check out the official documentation.

Learn more about GitHub with the Complete Git and GitHub for Beginners Bootcamp Bundle from TechRepublic Academy.

Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen.

Subscribe to the Developer Insider Newsletter

From the hottest programming languages to commentary on the Linux OS, get the developer and open source news and tips you need to know. Delivered Tuesdays and Thursdays

Subscribe to the Developer Insider Newsletter

From the hottest programming languages to commentary on the Linux OS, get the developer and open source news and tips you need to know. Delivered Tuesdays and Thursdays