linux下的git安装及配置

一.yum安装方式

1.安装

$ yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
$ yum -y install git-core
$ git --version
git version 1.7.1

2.配置

  • /etc/gitconfig 文件:系统中对所有用户都普遍适用的配置。若使用 git config 时用 --system 选项,读写的就是这个文件。
  • ~/.gitconfig 文件:用户目录下的配置文件只适用于该用户。若使用 git config 时用 --global 选项,读写的就是这个文件。
  • 当前项目的 Git 目录中的配置文件(也就是工作目录中的 .git/config 文件):这里的配置仅仅针对当前项目有效。每一个级别的配置都会覆盖上层的相同配置,所以 .git/config 里的配置会覆盖 /etc/gitconfig 中的同名变量。

如果用了 --global 选项,那么更改的配置文件就是位于你用户主目录下的那个,以后你所有的项目都会默认使用这里配置的用户信息。

如果要在某个特定的项目中使用其他名字或者电邮,只要去掉 --global 选项重新配置即可,新的设定保存在当前项目的 .git/config 文件里。

例如:

[root@master ~]# pwd

/root

[root@master ~]# git config --global user.name "maohx"

[root@master ~]# cat .gitconfig 

[user]

name = maohx

[root@master ~]# git config --global user.email mhx668@163.com

[root@master ~]# cat .gitconfig 

[user]

name = maohx

email = mhx668@163.com

[root@master ~]# pqd

-bash: pqd: command not found

[root@master ~]# pwd

/root

[root@master ~]#

二.下载tar.gz包安装方式

1、安装依赖包

yum install perl cpio curl curl-devel zlib-devel openssl-develexpat-devel gettex-devel -y

2、下载最新的Git包

https://www.kernel.org/pub/software/scm/git/git-2.17.0.tar.xz

3、解压并进入目录

xz -d git-2.17.0.tar.xz

tar -xvf git-2.17.0.tar

cd git-v2.17.0/

4、配置安装路径

./configure --prefix=/usr/git

5、编译并安装

make && make install

6、设置环境变量

echo "export PATH=/usr/git/bin:$PATH" >> /etc/profile

source /etc/profile

7、检查是否安装成功

git --version

posted @ 2018-04-25 17:42  mhx_pyw  阅读(310)  评论(0编辑  收藏  举报