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

相關文章
相關標籤/搜索