-
git多账号登陆问题
设置git全局设置:
git config --global user.name "your_name"git config --global user.email "your_email"需要取消git的全局设置:
git config --global --unset user.namegit config --global --unset user.email针对每个项目,单独设置用户名和邮箱,设置方法如下:
git config user.name "your_name" git config user.email "your_email"说白了,也就是进入到你的git项目相对根目录下,然后执行git config设置记录SSH配置(转的 未测试)
我看了很多中文博客,发现讲的都不太清楚,还是在*上,找了一个问题解决我的疑惑:http://*.com/questions/14689788/multiple-github-accounts-what-values-for-host-in-ssh-config
解决方法总结如下:
(1) 我现在有两个git项目,使用的用户名分别是A/B,用的邮箱分别是C/D
(2) 在~/.ssh目录下,使用 ssh-keygen -C "your_email" -t rsa 生成公私秘钥,命名分别为 id_rsa_first, id_rsa_second,公钥的内容需要分别上传到git项目的服务器上
(3) 在~/.ssh目录下创建config文件,进行相应配置:#第一个git项目账号 Host first HostName test.com #这里需要用真实的项目检出hostname,为了项目安全,我这里随意写的 User A IdentityFile ~/.ssh/id_rsa_first #第二个git项目账号 Host second HostName test2.com Port 1334 User B IdentityFile ~/.ssh/id_rsa_second
(4) 新建git项目检出目录,我发现很多同学出问题,在于git项目没有初始化
mkdir project && cd project git init git config user.name "A" git config user.email "C"
相应的第二个项目也参照上面的指令进行初始化设置
(5)检出服务端项目代码,这里需要注意,使用.ssh目录下的host代替真实的hostname,这样才能让git识别出来git remote add first git@first:A/project.git
如果使用的是repo,也是同样操作
repo init -u ssh://A@first -b branch
(6)push的时候,push到对应的Host即可
first项目中: git push fist master
相关文章
- coding上创建项目、创建代码仓库、将IDEA中的代码提交到coding上的代码仓库、Git的下载、IDEA上配置git
- 每个项目单独配置 git 用户
- Coding上创建项目、将IDEA中的代码提交到Coding上的代码仓库、Git的下载、IDEA上配置Git
- iis中为每个应用程序池单独设置aspnet.config配置文件
- Git配置用户信息和SSH
- Git配置用户信息和SSH免密
- Git安装、配置、上传公钥、测试登录及clone库(用户教程)
- 同一台机器配置多个Git用户
- maven 项目拆分配置文件为单独的项目(即maven项目如何依赖另一个项目的配置文件)
- spark 大型项目实战(六):用户访问session分析(六) --开发配置管理组件