我怎样才能在一个系统中配置两个不同凭据的git仓库? [英] How can I config two different git repo with different credentials in one system?

查看:560
本文介绍了我怎样才能在一个系统中配置两个不同凭据的git仓库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Local Repository-1



我一直在为我的组织申请git仓库克隆在C盘文件夹中的应用程序。
我已经设置了全局配置,并且能够执行提交,推送,拉取操作。这是我的组织的私人存储库,具有唯一的用户名,密码和网址。一切工作正常这个存储库。



问题



2
现在,我想在同一个系统上创建自己的github项目(与第一个不同)的本地存储库,但位于不同的位置。该存储库具有与同一系统上的其他存储库不同的配置。所以我担心的是,如何在同一客户端系统上维护特定于存储库的配置(用户名,密码,url)。

解决方案

您有以下2个选项,根据您的首选方式(ssh或password) / p>

基于SSH的访问: - 为您的公司git帐户创建2个ssh密钥对,并为您自己的git帐户创建一个。您需要通过以下公共ssh密钥 your-github-account /rel =nofollow noreferrer>这篇文章。



密码库访问: - 在这种情况下,您无需执行任何操作,只需输入用户名密码在git push等。



重要提示:现在您需要添加git configs (git用户名,电子邮件等),git可以选择在 gloabl 本地权限。我建议根据您的组织设置全局 user.email和user.name 设置,以避免提交给您的公司具有私人git用户名和电子邮件的repo。



例如在git命令下面会显示git的gloabl设置: -

  git config --global --list 
user.name =< firstname.lastname>
user.email =<公司邮件地址>

然后在您的私有git仓库中设置git用户名和密码,使用下面的命令

  git config --local user.nameamit
git config --local user.emailamit @ mail.com

您可以确认,您自己的私人回购没有,您的公司 git config --edit 命令或 git config --local --list


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.

解决方案

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.

这篇关于我怎样才能在一个系统中配置两个不同凭据的git仓库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆