Just use --local instead of --global.
In fact, local is the default so you can just do
in each repo:

$ git config user.email personal@example.org
$ git config user.name "whatf hobbyist"

Using Git’s credential helpers

https://git-scm.com/docs/gitcredentials

gitcredentials – providing usernames and passwords to Git

SYNOPSIS

$ git config credential.https://example.com.username <my_user_name>
$ git config credential.helper "$helper $options"

CONFIGURATION OPTIONS

  • helper
    The name of an external credential helper, and any associated options. If the helper name is not an absolute path, then the string git credential- is prepended.
$ git config --global credential.helper store

The store helper is the simplest helper which will save your credentials on disk protected only by file permissions.

  • username
    A default username, if one is not provided in the URL.
$ git config --global credential.username <YOUR_GIT_NAME>
  • useHttpPath
    By default, Git does not consider the “path” component of an http URL to be worth matching via external helpers. This means that a credential stored for https://example.com/foo.git will also be used for https://example.com/bar.git. If you do want to distinguish these cases, set this option to true.
$ git config --global credential.useHttpPath true

$ git credential fill 
protocol=https
host=mygithost

protocol=https 
host=mygithost
username=bob
password=s3cre7


$ git credential fill
protocol=https
host=unknownhost
Username for 'https://unknownhost': bob
Password for 'https://bob@unknownhost':
protocol=https
host=unknownhost
username=bob
password=s3cre7

Using Custom Helpers

http://kgrz.io/using-git-credential-helpers.html

There is another way to add programs that fetch user credentials. The program to run to fetch the credentials can be configured using three different ways. To quote the manual for git credentials:

REQUESTING CREDENTIALS
Without any credential helpers defined, Git will try the following strategies to ask the user for usernames and passwords:
1. If the GIT_ASKPASS environment variable is set, the program
specified by the variable is invoked. A suitable prompt is provided
to the program on the command line, and the user’s input is read
from its standard output.

  1. Otherwise, if the core.askPass configuration variable is set, its
    value is used as above.

Which means, we can set the path of the program we need to run in the configuration variable core.askPass and Git will run that program for the user specified.
An example program that would fetch the credentials might look like this:

$ vim ~/.git_credential_helper.rb

#!/usr/bin/env ruby
require 'open3'

USERNAME = 'computer_user_name'
ACCOUNTNAME = 'github_account_name'

command = "sudo -u #{USERNAME} /usr/bin/security -v find-internet-password -g -a #{ACCOUNTNAME} /Users/#{USERNAME}/Library/Keychains/login.keychain"

stdout_and_err = Open3.capture2e(command)
password =
 Array(stdout_and_err)
   .first
   .split("\n")
   .select { |x| x.start_with?("password") }
   .first
puts password.match(/\Apassword\: "(.*)"/).captures.first

Set the file as executable by running chmod +x ~/.git_credential_helper.rb and test it out.

Assuming you have a remote with the following URL https://github.com/myusername/mysecretproject, update the Git configuration to use the helper whenever it needs authentication:

$ git config --global \
credential.https://github.com/myusername/mysecretproject.username \
your_github_account_name

ex) Github: https://github.com/CodebitsDesign/angular2-mean-app.git

$ git config --global \
  credential.https://github.com/CodebitsDesign/angular2-mean-app.username CodebitsDesign

Note that the remote URL is appended with a trailing .username fragment which becomes the key and the GitHub username becomes the value. Check the file ~/.gitconfig under the [credentials] section to see how this structure looks.

Once the username is set, map the helper:

$ git config --global core.askPass ~/.git_credential_helper.rb

Summary of Git Credential

CONFIGURATION

$ git config --global credential.helper store
$ git config --global credential.username <YOUR_GIT_NAME>
$ git config --global credential.useHttpPath true

CUSTOM HELPERS

$ vim ~/.git_credential_helper.rb
... save above contents 

$ chmod +x ~/.git_credential_helper.rb

ex) Github: https://github.com/CodebitsDesign/angular2-mean-app.git
Username: CodebitsDesign
Update the Git configuration to use the helper whenever it needs authentication:

$ git config --global \
  credential.https://github.com/CodebitsDesign/angular2-mean-app.username CodebitsDesign

Once the username is set, map the helper:

$ git config --global core.askPass ~/.git_credential_helper.rb

Create a new repository on the command line

$ cd  angular2-mean-app/
$ echo "# angular2-mean-app" >> README.md
$ git init
$ git add README.md
$ git commit -m "first commit"
$ git remote add origin https://github.com/CodebitsDesign/angular2-mean-app.git
$ git push -u origin master
  ... git-credential helper is called...

Leave a Reply