开发学院

您的位置:首页>教程>正文

教程正文

Git 安装

Git 安装

  在使用Git之前,您必须安装并进行一些基本配置更改。以下是在Ubuntu和Centos Linux上安装Git客户端的步骤。

安装Git客户端

  如果您使用的是基于Debian的GNU/Linux发行版,那么apt - get命令就可以直接安装。

[ubuntu ~]$ sudo apt-get install git-core
[sudo] password for ubuntu:
[ubuntu ~]$ git --version
git version 1.8.1.2

  如果您使用的是基于RPM的GNN/Linux发行版,那么使用yum命令。

[CentOS ~]$
su -
Password:

[CentOS ~]# yum -y install git-core

[CentOS ~]# git --version
git version 1.7.1

自定义Git环境

  Git提供了git配置工具,它允许您配置变量。git将所有全局配置存储在位于主目录中的.gitconfig文中件。要将这些配置值设置为全局,请添加-global选项,如果忽略-global选项,则您的配置是针对当前Git存储库的。

  你也可以设置系统范围的配置。git将这些值存储在/etc/gitconfig文件中,该文件包含系统上每个用户和存储库的配置。要设置这些值,您必须拥有root权限并使用-system选项。

设置用户名

  Git每次提交时都会使用此信息。

[jerry@CentOS project]$ git config --global user.name "Jerry Mouse"

设置邮箱id

  Git每次提交时都会使用此信息。

[jerry@CentOS project]$ git config --global user.email "jerry@tutorialspoint.com"

避免拉取的时候合并提交

  您从远程存储库中提取最新的版本,如果这些版本不同,则默认情况下Git创建合并提交。我们可以通过以下设置来避免这种情况。

jerry@CentOS project]$ git config --global branch.autosetuprebase always

颜色高亮

  以下命令在控制台中启用Git的颜色高亮显示。

[jerry@CentOS project]$ git config --global color.ui true

[jerry@CentOS project]$ git config --global color.status auto

[jerry@CentOS project]$ git config --global color.branch auto

设置默认编辑器

  默认情况下,Git使用系统默认编辑器,我们可以通过使用git配置来配置不同的配置。

[jerry@CentOS project]$ git config --global core.editor vim

设置默认合并工具

  Git不启用用于将冲突更改集成到工作树中的默认合并工具。我们可以通过启用以下设置来设置默认合并工具。

[jerry@CentOS project]$ git config --global merge.tool vimdiff

列出Git设置

  要验证本地存储库的Git设置,请使用Git config -list命令,如下所示。

[jerry@CentOS ~]$ git config --list

  上述命令将产生以下结果。

user.name=Jerry Mouse
user.email=jerry@tutorialspoint.com
push.default=nothing
branch.autosetuprebase=always
color.ui=true
color.status=auto
color.branch=auto
core.editor=vim
merge.tool=vimdiff