Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I config two different git repo with different credentials in one system?

Tags:

git

github

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.

like image 502
Sandeep Kharat Avatar asked Mar 30 '17 12:03

Sandeep Kharat


1 Answers

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

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

Password bases 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 gloabl and local leval. I would recommend setting the user.email and user.name setting globally according to your organization, to avoid commit to your company repo which has your private git username and email.

for example below git command will show the gloabl 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 "[email protected]"

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.

like image 73
Amit Avatar answered Oct 11 '22 00:10

Amit