ubuntu安装配置git

安装git

sudo apt-get install git-core

设置用户名邮箱

git config --global user.name "jash king"
git config --global user.email xxx@gamil.com

安装wine(可选)

sudo apt-get install wine

安装的时候会停在一个"正在设定ttf-mscorefonts-installer"的界面,这时候要用tab键才能选中确定按钮继续

安装notepad++(如果用np++作为git默认编辑器)

  1. 到官网下载notepad++ 的windows安装包
  2. 下载完成后修改属性为可执行,然后用wine打开安装
  3. 配置git编辑器
git config --global core.editor 'wine C:\\Program\ Files\\Notepad++\\notepad++.exe -multiInst -nosession -noPlugin'

说明:

  • -multiInst: 允许打开多个notepad++
  • -nosession: 不打开一起的会话,也不保存本次会话
  • -noPlugin: 不加载插件

用sublime text作为git默认编辑器(推荐)

  1. 安装sublime text,参考sublime text 2 安装
  2. 打开sublime,选择Preferences -> Settings - Default,将hot_exit和remember_open_files都改为false
  3. 配置git编辑器
git config --global core.editor 'sublime -n -b -w'

安装p4merge差异分析工具

  1. 到官网下载p4merge 的linux版
  2. 将解压出来的bin, lib文件夹复制到/user/bin, /user/lib
  3. merge配置
    git config --global merge.tool p4merge
    git config --global mergetool.prompt true
    git config --global mergetool.trustExitCode true
    git config --global mergetool.keepBackup false
    git config --global mergetool.p4merge.cmd 'p4merge $BASE $LOCAL $REMOTE $MERGED'
    
  4. diff配置
    git config --global diff.tool p4merge
    git config --global difftool.prompt false
    git config --global difftool.p4merge.cmd 'p4merge $LOCAL $REMOTE'
    

其他配置

git config --global core.autocrlf true
git config --global core.safecrlf true
git config --global alias.hist 'log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short'

说明:

  • autocrlf:设为false,禁止git对换行符进行转换,设为true,提交时git会将文件中的CRLF(\r\n)转换为LF(\n),这样拉代码到本地时又将LF转为CRLF,设为auto,则提交时转换,拉取时不转换。如果跨系统工作(windows和linux),最好设为true
  • safecrlf: 设为true,拒绝提交含有混合换行符的文件,设为false,允许提交
  • prompt: 如果设为false,则每次使用difftool和mergetool时git就不会提示是否使用外部工具
  • trustExitCode: 设为true,这样每次使用mergetool,退出p4merge时,git就会认为merge完成,设为false,退出的时候git会进行询问
  • keepBackup: 设为true,这样merge时就不会备份目标文件,设为false,merge完成会生成一个备份文件

生成ssh key连接github

  1. 生成密钥对
    ssh-keygen -t rsa -C 'xxx@gamil.com'
    

    密钥文件生成成功后会在主目录下产生.ssh文件夹,里面id_rsa文件是私钥,id_rsa.pub是公钥

  2. 打开https://github.com,进入个人账户Account settings -> SSH Keys菜单,选择Add SSH key按钮,将id_rsa.pub文件中的内容复制进去,然后点确定按钮完成添加