Environment setup

Before officially using Git, you should first install Git and complete some basic configurations. This chapter will teach you how to install Git on Ubuntu and CentOS.

Install Git client

If you are using a Debian-based Linux distribution, you should use the apt-get command to complete the installation operation. If you can find the Git version as follows, the installation is successful:

[jerry@CentOS ~]$ sudo apt-get install git-core
password for ubuntu:

[jerry@CentOS ~]$ git --version
git version 1.8.1.2

If you are using an RPM-based Linux distribution, you should use the yum command to complete the installation. You can also use the Git command to complete the installation:

$ su -
Password:

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

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

Set up the Git environment

Git provides a Git configuration tool that allows you to set environment variables. Git stores all global variables in the .gitconfig file, which is located in your home directory. To set global variables, you need to add the --global option. If you do not add this option, the variables you set will only be used in the current Git repository.

You can also set variables that can take effect in the entire system. Git stores these variables in the /etc/gitconfig file, which has configurations applicable to each user and warehouse in the system. To set these variable values, you must have root user authority and the option --system

If the above installation work is completed, you can perform the following configuration work————

Set username

This setting will be used for every commit operation of Git:

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

Set up email

Same as above, this setting will also be used for each submission operation:

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

Prevent merging during pull operations

When you pull the latest changes from a remote repository, if these changes and commits conflict with each other, then Git will create a merge commit by default. We can avoid this kind of merge by setting the following:

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

Color highlight

The following command makes the Git color highlight available in the console:

[jerry@CentOS ~]$ git config --global color.ui true
[jerry@CentOS ~]$ git config --global color.status auto
[jerry@CentOS ~]$ git config --global color.branch auto

Set the default editor

By default, Git uses the system default editor, which is determined by the system environment variables VISUAL and EDITOR . We can also use the git config command to set a favorite editor by ourselves, as follows to set vim as the default editor:

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

Set default merge tool

Git does not provide a merge tool for integrating conflict modification submissions. We can set one by ourselves through the following command:

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

List all settings of Git

To verify whether your settings are set in the local warehouse, you can use the git config --list command to view:

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

If all the steps are performed according to the commands described above, the displayed result should be as follows:

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

Learn programming, don't rush for success, be sure to read more classic books, read more source code, and work hard to smash the code, so that the technology can grow. To share with you some classic books that programmers must read, be sure to read them several times:

Give it to everyone for free, just ask you to give me a thumbs up!

Programmer must-read classic book list (HD PDF version)

Gain? I hope that the old guys will have a three-strike combo, so that more people can read this article

Recommended reading:

Welcome to follow my blog: Liang Xu Linux Tutorial Network , full of dry goods!


良许
1k 声望1.8k 粉丝