android studio git 更换账号 git怎么切换账号 您所在的位置:网站首页 git图形界面怎么更换用户密码 android studio git 更换账号 git怎么切换账号

android studio git 更换账号 git怎么切换账号

2024-06-02 20:42| 来源: 网络整理| 查看: 265

查看本地仓库提交代码账号和邮箱

进入仓库目录(即带有.git文件夹的目录)

方法一 打开git命令行(git bash here) ,执行以下命令 git config user.name git config user.email方法二 进入.git文件夹,打开config文件,其中[user]即是该仓库的提交代码的账号和邮箱,仓库级别[core] repositoryformatversion = 0 filemode = false bare = false logallrefupdates = true symlinks = false ignorecase = true [remote "origin"] url = [email protected]:xxx/yyy.git fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/master [user] name = xxx email = [email protected]

注意:以下命令是设置全局提交代码账号,即本机所有仓库共用的提交代码账号 git config --global user.name “Your_username” git config --global user.email “Your_email” 执行命令后会在本机用户目录下生成.gitconfig文件,内容为

[user] name = sss email = [email protected]查看仓库关联git账号检查当前登录账号 ssh -T git@github2,其中github2是配置的git仓库host检查当前秘钥 ssh-add -l切换本机某仓库关联的git账号(SSH方式)

前提:github1,github2是两个qithub账号,本机某仓库的git账号关联的是github1 需求1、git关联账号不变,改变提交代码的user.name

切换到仓库目录,执行以下git命令,即可实现提交代码时,记录的是新账号,用github1登录github,查看活动记录仍在github1中,新名字可以不必是github账号,邮箱也不是必填 git config user.name “新名字” git config user.email “新名字邮箱”

需求2、切换本地仓库关联的github账号为github2,活动记录在github2上

本机创建github2(邮箱地址,且该账号必须是github的用户)的ssh key,注意key文件与已有账号的key文件区分开

android studio git 更换账号 git怎么切换账号_git

将生成的新秘钥添加到ssh-agent ssh-agent bash ssh-add ~/.ssh/id_rsa_sina添加host 在~/.ssh目录下找到config文件,如果没有就创建 touch config config文件内容# 该文件用于配置私钥对应的服务器 # Default github user([email protected]) Host github1 HostName github.com User git1 IdentityFile C:/Users/XX/.ssh/id_rsa # second user([email protected]) # 建一个github别名,新建的帐号使用这个别名做克隆和更新 Host github2 HostName github.com User git2 IdentityFile C:/Users/XX/.ssh/id_rsa_sina

其规则就是:从上至下读取config的内容,在每个Host下寻找对应的私钥。这里将GitHub SSH仓库地址中的[email protected]替换成新建的Host别名如:github2,那么原地址是:[email protected]:xxx/bbb.git,替换后应该是:github2:xxx/bbb.git.

将新生成的公钥添加至github2的账号中

android studio git 更换账号 git怎么切换账号_提交代码_02

修改仓库提交代码的user.name和user.email git config user.name “新账号” git config user.email “新账号邮箱”修改本地仓库的远程库的url,host换成步骤3中新账号配置的host $ git remote set-url origin git@github2:xxx/bbb.git 至此,该仓库账号切换完成。检查当前登录账号 ssh -T git@github2检查当前秘钥 ssh-add -l切换回github1时,只需执行步骤5和6,把6的host换成github1的host即可

参考资料本地配置远程库地址的命令生成SSH key



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有