August 07, 2021
Recently, one of my PR got merged in React Core. I was over the moon to see it merged and I took a screenshot and shared it on social media. I was quite happy thinking my name would now show up in the contributors’ section in the GitHub repository of
facebook/react. But here is the twist - it was not!
Normally the name shows up in GitHub if you have even one single PR. It got me thinking why wasn't my name on that list. I had configured the SSH correctly for work and private GitHub; then why would this happen?
I had to go back and figure out how GitHub shows the contribution chart.
When you first install the git in your system, you have to provide two values to the local git - your name and your commit email. Then, when you commit anything in any git repository, it associates those two values with the commit. So, when I set up the git first time in the current system it was my work email. This meant all of the commits I did during the last six months were signed by my work email. And I thought I knew enough git to be dangerous!
Next thing I did was to search if we can use different emails for different projects. One solution was to setup an email for every folder, which is not practical if you clone git repos every now and then. Instead, I needed a generic workflow that could help me use different emails for different folders. I had already segregated folders for work and private so that would have been a more natural solution for the way I organize git repos in my system.
I have found a solution to this problem.
Conditional Configuration was released to git back in 2017. For future me, I am writing this blog listing all the configurations I need when setting up git in a new machine.
ssh-keygen -t ed25519 -C "[email protected]"
eval "$(ssh-agent -s)" to
ssh-add -K ~/.ssh/id_ed25519
~/.ssh folder (example)
.gitconfig for different situations
name = Shubham Pandey
email = [email protected] # default email if no config provided
useConfigOnly = true
[includeIf "gitdir:~/mysites/work/"] # For Work folder
path = ~/mysites/work/.gitconfig # use this config file, you can define them in any folder
[includeIf "gitdir:~/mysites/experiment/"] # For Personal folder
path = ~/mysites/experiment/.gitconfig # use this config file
email = [email protected]
name = Shubham pandey
That's it. Now you have configured two different emails for two different folders, now I can commit in peace. Hopefully, my next PR to react comes sooner.