How can I config two different git repo with diffe

2020-03-06 19:41发布

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.

标签: git github
1条回答
▲ chillily
2楼-- · 2020-03-06 20:14

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 "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.

查看更多
登录 后发表回答