21

Local Repository-1

I have been working on application for my organization whose git repository cloned at C drive folder. I have set global configurations, and I have been able to perform commit, push, pull operations. This is private repository of my organization with unique user name, password and url. Everything working fine this repository.

Problem

Local Repository-2 Now, I want to create local repository of my own github project (different from first one) on the same system, but on different location. This repository have different configurations than other repository on the same system. So my concern is, how can I maintain repository specific configurations(user name, password, urls) on the same client system.

Sandeep Kharat
  • 500
  • 1
  • 4
  • 12
  • What do you mean, exactly? Are you using a different public key for this repository, or do you want to set a different name/email combination for this repository? – Makoto Mar 30 '17 at 16:30
  • I have explained my problem in detail. Thanks for the reading my problem. – Sandeep Kharat Mar 31 '17 at 05:35
  • The answer from Amit is fine if you are okay with setting up every repo separately. There is an alternate method that will set up credentials for every repo nested in a given folder. See [this Answer](https://stackoverflow.com/a/43654115/6501141). – LightCC Sep 14 '22 at 18:36

1 Answers1

37

You have the below 2 options, Based on your preferred way (ssh or password) based access to git account:-

SSH based access:- create 2 ssh key-pairs one for your company git account and one for your own git account. you need to add public ssh keys on both the git accounts by following this article.

Password based access :- In this case you don't need to do anything, you just need to give the username and password on git push etc.

Important:- Now you need to add the git configs (git username, email etc) for your system, git has option to set these at global and local leval. I would recommend setting the user.email and user.name setting globally according to your organization, to avoid commits to your company repo which has your private git username and email.

For example below git command will show the global setting of git :-

git config --global --list
user.name=<firstname.lastname>
user.email=<company mail address>

And to set the git username and password in your private git repo, use below command, inside your repository

git config --local user.name "amit"
git config --local user.email "amit@mail.com"

You can confirm, that your own private repo does not have, your company username and password by running git config --edit command or git config --local --list.

Amit
  • 30,756
  • 6
  • 57
  • 88
  • glad to know that @SandeepKharat – Amit Apr 03 '17 at 08:56
  • there is no need to have a global config is there? can't you just have local configs – simplename Nov 17 '21 at 00:47
  • 1
    in your last code snippet you don't actually set the password – Madbreaks Aug 06 '22 at 18:33
  • No need for 2 ssh key pairs. – Tobias Cudnik Aug 10 '22 at 09:11
  • Same comment as @TobiasCudnik - no need for multiple SSH keys. Just upload the public key to every remote you need to connect to. The public key does not allow someone that has it to act as you - only to authenticate that it is you connecting to them. There is no security issue with uploading the same public key multiple places. The security issue is if you move your private key. Do not copy it to a USB or move it to another PC. Create a separate SSH key pair for every device you use and upload the separate public key to each account that needs it... – LightCC Sep 14 '22 at 18:22