0

I am using Github for the personal repositories and GitLab for the companies team repositories.

Thanks to [1] and [2], I was able to separate personal repositories with the work repositories (in the context of git account info) like below gitconfig script.

However, I still couldn't separate the git credentials. Thus, I have to write ids and passwords every time they are required. Can someone help me separating the git credentials by the working directory for two different git accounts like the below config files?

~/.gitconfig

[user]
        email = personal@gmail.com
        name = My Name

[includeIf "gitdir:~/repositories/work/"]
        path = ~/repositories/work/.gitconfig

~/repositories/work/.gitconfig

[user]
        email = MyName@company.com
        name = My Name

p.s. My setting is git 2.25.x and Ubuntu 20.04.

Jiho Choi
  • 1,083
  • 1
  • 10
  • 26
  • 1
    why don't you use ```git config --local``` https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration – Kristian Feb 13 '21 at 19:45
  • Thanks for the reply. I believe the local option is for each repository not for the whole repositories under the specified directory (like `./work/`). – Jiho Choi Feb 14 '21 at 12:16
  • 1
    by git credentials, do you mean username and password that are required when you push via https to remote repo? if yes, why don't you just use ssh keys? – Kristian Feb 14 '21 at 12:27

1 Answers1

0

I end up separating the git config files and git credentials as below. The below setting ables me to separate all repositories' credentials from that of under work/ directory.

(Didn't know that .git-credentials automatically handles it by appending the credentials in plain text.) Thanks.

  1. ~/.gitconfig
[user]
        email = personal@gmail.com
        name = My Name

[includeIf "gitdir:~/repositories/work/"]
        path = ~/repositories/work/.gitconfig

[credential]
        helper = store
  1. ~/repositories/work/.gitconfig
[user]
        email = MyName@company.com
        name = My Name

[credential]
        # (or) helper = cache --timeout 86400
        helper = store
Jiho Choi
  • 1,083
  • 1
  • 10
  • 26