All Articles

Setup git config for project

Problem

Normally, we setup git username and email globally with following commands:

git config --global user.name "FIRST_NAME LAST_NAME"
git config --global user.email "MY_NAME@example.com"

This is not convenience if we are using one PC for multiple organization. For example, use your PC for both company works and your side projects.

Solution

To configure username and email within project. Go to git repository and run commands:

git config user.name "FIRST_NAME LAST_NAME"
git config user.email "MY_NAME@example.com"

Here, we remove --global parameter. We can check the configuration with following command:

cat .git/config

It should output something like this:

$ cat .git/config
[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
	ignorecase = true
	precomposeunicode = true
[remote "origin"]
	url = git@github.com:phuongnq/phuongnq.dev.git
	fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
	remote = origin
	merge = refs/heads/master
[user]
	name = Phil Nguyen
	email = nquangphuong@gmail.com