Home » Git » How to set git config username and email

How to set git config username and email

By Emily

Following on from my previous post which explains how to get your git config username and email, in this post I’ll explain how to set your git config username and email. You can set them at a global level and in each repo locally, so I’ll provide examples of how to do both.

What is your git username for?

There needs to be a username associated with every commit to a repo. You can change your username at any time but if you do, it will not change the username that was associated with any past commits.

You can have a username configured globally, which will then be used for every single repo when you commit, or you can set up a local, repo specific username.

When you commit, git will look for a local setting first, and if it can’t find one, will use the global setting.

How to set your global git config user.name

To set the username globally you use the git config command with the --global flag.

git config --global user.name "Jane Doe"

This will have set your git config username to “Jane Doe”.

How to set your local git config user.name

To set the username locally you use the same command but without the global flag, because git defaults to setting it locally. But bear in mind when you set the git config username or email locally, you need to make sure you are in the correct repo before you use the command – it will set the username or email for the repo you are in.

So navigate to the correct folder and then use this command:

git config --global user.name "Jack Johnson"

Now you’ve set the user name for that repo to “Jack Johnson”.

How to check your git config username

I’ve written a whole post which explains how to check what your git config values are. So once you’ve done the above you can use the commands described in there to see them.