git在各操做系统平台下的安装和配置

git在各操做系统平台下的安装和配置

标签 : gitlinux


[TOC]git


本文是git系列博客的第一篇,主要介绍git在windows,linux,Mac OX等不一样操做系统下的安装和配置,主要之后二者为主。github

工具下载

  • ubuntu:sudo apt-get intall git 安装
  • windows:下载git for windows安装便可
  • mac:我的对homebrew不是很安心,建议安装macports,再用macports安装git(sudo port install git +bash_completion)

环境相关配置

  • git config --global user.email "you@example.com" 配置邮件
  • git config --global user.name "Your Name" 配置用户名
  • git config --global color.ui true 开启颜色显示
  • 建立SSH Key。在用户主目录下(~),看看有没有.ssh目录,若是有,再看看这个目录下有没有id_rsaid_rsa.pub这两个文件,若是已经有了,可直接跳到下一步。若是没有,打开Shell(Windows下打开Git Bash),建立SSH Key:ssh-keygen -t rsa -C "youremail@example.com"
  • 登录GitHub,打开“Account settings”,“SSH Keys”页面。而后,点“Add SSH Key”,填上任意Title,在Key文本框里粘贴.ssh目录下id_rsa.pub文件的内容,点“Add Key”

命令行显示配置

  • 提示语换英语,mac下在.bash_profile里添加下面内容,ubuntu在~/.profile下添加
# git language
export LANGUAGE='en_US.UTF-8 git'
  • 终端显示分支,mac下在.bash_profile里添加下面内容
# Git branch in prompt.

parse_git_branch() {
    git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\u@\h:\w\[\033[32m\]\$(parse_git_branch)\[\033[00m\]$ "

参考Add Git Branch Name to Terminal Prompt (Mac)shell

git补全

若是是linux或者windows用户,通常不会出现这个问题,mac下我当时是bash环境没设置好,按照这篇文章安的,使用的是Command Line Tools安装的git,不能识别macports里的git的补全。有几种办法能够彻底补全ubuntu

  • 方法一:直接下载补全文件并使其生效

参考git auto-complete for branches at the command line?windows

1.经过curl下载:curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bashbash

2.在~/.bash_profile里添加app

if [ -f ~/.git-completion.bash ]; then
  . ~/.git-completion.bash
fi
  • 方法二:使用macports的bash环境

参考:How to use bash-completionssh

检查的下本身的bash:which bash,which -a bashcurl

  • 方法三:使用oh-my-zsh并启用git plugins

检查下支持的shell:cat /etc/shells 查看当前shell:echo $SHELL

参考资料


做者@brianway更多文章:我的网站 | CSDN | oschina

相关文章
相关标签/搜索