我在 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中切换用户身份
发布评论