Do you have Personal GitHub
and Work
related GitHub account? I’m sure you do. Most of the fortune 500 companies are now using GitHub as their official code repository.
By default /<Users>/.gitconfig
file is used for all related information during commit.
This is how .gitconfig
file looks like:
[user] name = Crunchify email = email [at] crunchify.com [pull] rebase = false [commit] gpgSign = false [gui] pruneduringfetch = true [smartgit "submodule"] fetchalways = true update = true initializenew = true [push] recurseSubmodules = check
As you see above, there is tag called [user]
all git clients including smartGit picks up that username
, email
and will push using that setting.
This is a big problem for your Work and Personal Github or Bitbucket account. You need to be very careful before committing to each repository.
By default hidden .gitconfig
file is use for both account and there is no way you could separate out different .gitconfig file for each account
If you have any of below questions then you are at right place:
- Setting your commit username and email address in Git
- Set GitHub email address on a per repository basis
- GIT – different config for different repository
- How can I change the author (name / email) of a commit?
- How to Change Author Name and Email of Commits on macOS?
- GitHub change email for repository
In this tutorial we will go over steps on how to use different setting for different repositories:
Step-1
Clone your Work repository and Private repository to your laptop/desktop. Here is example I’ve shown total 5 Crunchify repositories.
We will use different username and email for each repository.
Step-2
- Go to repository
- Click on hidden folder
.git
- Open
config
file
Step-3
Add [user]
tag with username and email info. Here is a sample.
config file:
[core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true ignorecase = true precomposeunicode = true [remote "origin"] url = https://github.com/Crunchify/CrunchifyTutorials fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/master [user] name = Crunchify, LLC email = email [at] crunchify.com
Using command line also you could to change the file.
- Open macOS Terminal.
- Change the current working directory to the local repository
- This is a repository where you want to configure the name that is associated with your Git commits.
- Execute command:
git config user.email "email [at] crunchify.com"
- Execute command:
git config user.name "Crunchify, LLC"
That’s it.
Now you could use different username/email for each separate github or bitbucket repository.
The post How to set GitHub user.name and user.email per Repository? Different .config file for different Repository appeared first on Crunchify.
0 Commentaires