Configuring Git From A Fresh Install

Configuring Git From A Fresh Install
Photo by Praveen Thirumurugan / Unsplash

When setting up a fresh install of Git, it's often a best practice to go an configure some basic settings like username and email.

Setting The Username And Email In Git Globally

The following command will setup your global username and email across all of your repositories. Just make sure you change the values or my fake email will get all the credit for all of your commits

git config --global "user.name" "David Boothe"
git config --global "user.email" "david@ihatespam.com"

Setting The Username And Email Per Repository

If you have a mix of personal projects and work projects, then you might want to set the username and email to be different for a specific repository. If that is the case, then navigate to the folder of your unique project and use the same command above, but remove the --global parameter.

git config "user.name" "David Boothe"
git config "user.email" "david@ihatespam.com"

Viewing Git Config Settings

you can verify the current settings with the following git command:

git config --list

Setting Default Branch

I believe current default branch for Git is now main. I don't really have a dog in the fight between master vs main other than feeling dumber anytime I have to talk about it. But if you want to change your default branch to something else (like maybe develop), you can use the following command:

git config "init.defaultbranch" "develop"

Configuring Git to Always Rebase When Pulling From A Remote

One of the other settings I always change with a fresh install of Git, is to have Git always rebase when pulling from a remote.

Word of warning, rebase can be a destructive command in Git. Use with caution. Check out this Stack Overflow to see when should I use git pull --rebase

That being said, I hate unnecessary merge commits created from the default pull. Of course, I could always use the command

git pull --rebase

but I became a programmer so I could be lazy, and lazy means typing less stuff whenever possible. You can configure this setting in Git with the following command:

git config "pull.rebase" "true"

What Did I Miss?

Did I miss a Git configuration that you normally use? Let me know in the comments.