每个项目单独配置 git 用户
2016-01-24 01:30
323 查看
git多账号登陆问题
git config --global user.email "your_email"
需要取消git的全局设置:
解决方法总结如下:
(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文件,进行相应配置:
(5)检出服务端项目代码,这里需要注意,使用.ssh目录下的host代替真实的hostname,这样才能让git识别出来
设置git全局设置:
git config --global user.name "your_name"git config --global user.email "your_email"
需要取消git的全局设置:
git config --global --unset user.name git config --global --unset user.email针对每个项目,单独设置用户名和邮箱,设置方法如下:
git config user.name "your_name" git config user.email "your_email"说白了,也就是进入到你的git项目相对根目录下,然后执行git config设置记录
SSH配置(转的 未测试)
我看了很多中文博客,发现讲的都不太清楚,还是在stackoverflow上,找了一个问题解决我的疑惑:http://stackoverflow.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
相关文章推荐
- 一种局域网机器定时备份方案
- Influencer Finder
- the requested resource is not available
- Git push本地代码到新建远程仓库
- android studio中HttpClient解决
- BestCoder Round #69 (div.2) B HDOJ5611 Baby Ming and phone number(stl)
- 树莓派使用360wifi2实现无线上网
- ios开源库
- 用redis实现有优先级的"celery"
- 什么是 block
- Unique Path II
- VS2012中C语言不支持匿名联合,导出函数不界定范围
- 最大子数组
- ddd
- 每天学点Linux(一)
- Range of Intervals
- c++中extern的用处
- Makefile笔记A
- 总结 №3
- 图解kafka中的partition