在一台计算机上的一个Git中切换用户身份

编程入门 行业动态 更新时间:2024-10-07 10:21:19
本文介绍了在一台计算机上的一个Git中切换用户身份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在 GitHub 上拥有 ONE 存储库,我们称它为 Repo-1 。

我想首先以默认Git用户的身份访问该存储库。

让我们称该用户为 User-1 。

我创建了 SSH密钥对,一切正常, 。。我在 GitHub 上创建了另一个存储库>,我们称它为 Repo-2 。

I 没有在本地Git中做任何更改,在我的笔记本电脑上。现在,我想从 Repo-1 作为用户2 (但是来自同一台笔记本电脑的)。

首先所有:这是可以做到的吗?

本地Git可以在一台笔记本电脑上在用户帐户之间切换,并将其自身显示为用户-2 ?然后,从这个身份,从Repo-1克隆,做一些改变,然后推到 Repo-1 ?

如果可能的话,我该怎么做?

解决方案

您的全球.gitconfig已经配置了您的SSH密钥/用户信息。全局.gitconfig被本地gitconfig覆盖 - 文件config在您的.git文件夹中(如果它不存在,您可能必须创建它)。

例如,您可以将.gitconfig文件复制到.git文件夹中(并将其重命名为config),然后只更改要更改的行(可能是github.user和github.token),或者仅使用刚刚创建的新文件如果你喜欢命令行git config,你可以通过省略--global选项来避免所有的文件移动。

I have ONE repository on GitHub, let's call it Repo-1.

I want to first access that repository as a default Git user.

Let's call that user User-1.

I created SSH keypair, everything fine, works nice.

I made ANOTHER repository on GitHub, let's call it Repo-2.

I didn't make any changes in local Git, on my laptop. No configurational changes, nothing.

Now - I want to clone from Repo-1 as the User-2 (but from the same laptop).

First of all: is this at all possible to do?

Can local Git on one single laptop switch between "user accounts" and present itself as User-2? And then, from THAT identity, clone from Repo-1, make some change, and then push to Repo-1?

If possible, how do I do that?

解决方案

You have your global .gitconfig where you already configured your SSH Keys/User Information. The global .gitconfig is overridden by a local gitconfig - the file "config" in your .git folder (if it does not exist you might have to create it).

For example you can copy the .gitconfig file into the .git folder (and rename it to "config") and just change the lines you want to change (probably github.user and github.token) or you create a new file with just the two lines in it.

If you prefer the command line "git config" you can avoid all the file moving stuff by omitting the "--global" option.

更多推荐

在一台计算机上的一个Git中切换用户身份

本文发布于:2023-07-22 14:56:58,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:一台   机上   身份   用户   Git

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!