Advertisement
Guest User

Untitled

a guest
May 16th, 2017
619
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. 一、
  2. 安装完成git后,首先设置以下基本内容
  3.  
  4. git config --global user.name "XXX" # 换成你自己的名字
  5. git config --global user.email "XXX@yy.com" # 换成自己的邮箱
  6. git config --global push.default simple # 要是你非要用低版本的Git(比如1.7.x),好吧,那就不设simple设current,否则你的Git不支持
  7. git config --global core.autocrlf false # 让Git不要管Windows/Unix换行符转换的事
  8. git config --global gui.encoding utf-8 # 避免git gui中的中文乱码
  9. git config --global core.quotepath off # 避免git status显示的中文文件名乱码
  10. git config --global merge.tool "kdiff3" # 要是没装KDiff3就不用设这一行
  11.  
  12. windows 还需配置
  13.  
  14. git config --global core.ignorecase false
  15.  
  16. 二、
  17. 设置常用的alias
  18.  
  19. git config --global alias.co checkout
  20. git config --global alias.br branch
  21. git config --global alias.ci commit
  22. git config --global alias.st status
  23. git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'
  24. --abbrev-commit"
  25. git config --global alias.pl pull --allow-unrelated-histories
  26. git config --global alias.last 'log -1 HEAD'
  27.  
  28. 三、
  29. 设置SSH
  30. 为工作环境和非工作环境(如github)生成不同的 ssh key,然后一路回车,不要输入任何密码之类,生成ssh key pair
  31.  
  32. ssh-keygen -t rsa -f ~/.ssh/id_rsa_work -C xxx@yy.com
  33. ssh-keygen -t rsa -f ~/.ssh/id_rsa_pub -C xxx@zz.com
  34.  
  35. 把id_rsa_xxx.pub中的公钥内容复制到 gitlab/github 上,注意copy上开头的 ssh-rsa 这几个字
  36.  
  37. 如果在Linux上,需要把其中的私钥告诉本地系统:
  38.  
  39. ssh-add ~/.ssh/id_rsa
  40.  
  41. 编辑 ~/.ssh/config,设定不同的git 服务器对应不同的key
  42.  
  43. # Default github user(first@mail.com),注意User项直接填git,不用填在github的用户名
  44. Host github.com
  45. HostName github.com
  46. User git
  47. IdentityFile ~/.ssh/id_rsa_pub
  48.  
  49. # second user(second@mail.com)
  50. # 建一个gitlab别名,新建的帐号使用这个别名做克隆和更新
  51. Host 172.16.11.11
  52. HostName 172.16.11.11
  53. User work
  54. IdentityFile ~/.ssh/id_rsa_work
  55.  
  56. 注意git会用用户设置的名字和邮箱记录提交信息。在有多个git环境时,如果某个环境用来提交的用户名字和邮箱与global配置不同,那么就进到这些本地repository的目录后,执行类似下面命令
  57.  
  58. git config user.name "solarknight"
  59. git config user.email "zhouthanos@gmail.com"
  60.  
  61. 编辑完成后可以使用命令 ssh -vT git@github.com 看看是不是采用了正确的id_rsa_github.pub文件
  62. 这样每次push的时候系统就会根据不同的仓库地址使用不同的账号提交了
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement