[Git topic] environment construction

Environment construction

Before using Git formally, you should first install Git and complete some basic configurations. This chapter teaches 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. 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. If you can also use the Git command, the installation is successful:

$ su -
Password:

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

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

Set up Git environment

Git provides git configuration tools that allow 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 don't add this option, the variables you set can only be used in the current git warehouse.

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

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

Set user name

This setting will be used for each Git commit operation:

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

Set mailbox

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 operation

When you pull the latest changes from the remote warehouse, if these changes are submitted in conflict with each other, Git will create a merge submission by default. We can avoid such merging through the following settings:

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

Color highlight

The following command makes Git color highlighting 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 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 git config to set a favorite EDITOR, as follows: 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 submission. We can set one ourselves through the following command:

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

Lists all settings for Git

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

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

If all steps are operated according to the commands described above, the display results shall 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

When learning programming, don't be eager for success. You must read more classic books, read more source code, and work hard to knock the code. Only in this way can the technology grow. Share some classic books that programmers must read. Be sure to read them several times:

Free to everyone, just ask everyone to give me a praise!

Classic book list for programmers (HD PDF version)

Have you got anything? I hope the old fellow will take three strikes to show this article to more people.

Recommended reading:

Welcome to my blog: Liangxu Linux tutorial network , full of dry goods!

Tags: Linux Back-end server

Posted on Fri, 26 Nov 2021 16:49:29 -0500 by rickmans