YouTip LogoYouTip

Git Install Setup

We need to install Git before using it. Git currently supports running on Linux/Unix, Solaris, Mac, and Windows platforms. The download address for Git installation packages on various platforms is: [http://git-scm.com/downloads](http://git-scm.com/downloads) [!(#)](http://git-scm.com/downloads) * * * ## Installation on Linux Platform Major Linux platforms can use package managers (apt-get, yum, etc.) for installation. The command to install the latest stable version of Git on Debian/Ubuntu is: apt-get install git ### Centos/RedHat If you are using Centos/RedHat, the installation command is: yum -y install git-core Fedora installation command: # yum install git (Fedora 21 and earlier versions)# dnf install git (Fedora 22 and later versions) FreeBSD installation command: pkg install git OpenBSD installation command: pkg_add git Alpine installation command: apk add git ### Source Code Installation We can also download the source code package from the official website for installation. The latest source code package download address: [https://mirrors.edge.kernel.org/pub/software/scm/git/](https://mirrors.edge.kernel.org/pub/software/scm/git/). !(#) You can also clone the source code package on GitHub: git clone https://github.com/git/git Extract and install the downloaded source code package: $ tar -zxf git-1.7.2.2.tar.gz $ cd git-1.7.2.2 $ make prefix=/usr/local all $ sudo make prefix=/usr/local install * * * ## Installation on Windows Platform Installing Git on the Windows platform is also easy. A project called msysGit provides an installation package. You can go to the GitHub page to download the exe installation file and run it: Installation package download address: [https://gitforwindows.org/](https://gitforwindows.org/) You can also download it directly from the official website: [https://git-scm.com/download/win](https://git-scm.com/download/win). !(#) After downloading, double-click the installation package. The interface opens as shown below. Click the "next" button to start the installation: !(#) After completing the installation, you can use the command-line git tool (which already includes an SSH client), and there is also a graphical Git project management tool. Find **"Git"->"Git Bash"** in the start menu. A Git command window will pop up where you can perform Git operations. ### Using the winget tool If you already have winget installed, you can use the following command to install Git: winget install --id Git.Git -e --source winget * * * ## Installation on Mac Platform Install via Homebrew: brew install git If you want to install git-gui and gitk (Git's commit GUI and interactive history browser), you can install them using Homebrew: brew install git-gui You can also use the graphical Git installation tool. The download address is: [https://sourceforge.net/projects/git-osx-installer/](https://sourceforge.net/projects/git-osx-installer/) The installation interface is as follows: !(#) * * * ## Git Configuration Git provides a command called `git config` to configure or read corresponding working environment variables. These environment variables determine the specific working methods and behaviors of Git in various aspects. These variables can be stored in three different places: * `/etc/gitconfig` file: Configuration applicable to all users in the system. When using the `--system` option with `git config`, this file is read or written. * `~/.gitconfig` file: The configuration file under the user's directory applies only to that user. When using the `--global` option with `git config`, this file is read or written. * Configuration file in the Git directory of the current project (i.e., the `.git/config` file in the working directory): The configuration here is only effective for the current project. Configuration at each level overrides the same configuration at higher levels, so the configuration in `.git/config` will override variables with the same name in `/etc/gitconfig`. On Windows systems, Git looks for the .gitconfig file in the user's home directory. The home directory is the directory specified by the $HOME variable, usually C:Documents and Settings$USER. Additionally, Git will also attempt to find the /etc/gitconfig file, but it depends on where Git was originally installed as the root directory for locating it. ### User Information Configure personal user name and email address. This is to record the committer's information each time code is submitted: git config --global user.name "" git config --global user.email test@.com If the **--global** option is used, then the configuration file being changed is the one located in your user home directory. All your projects will use the user information configured here by default. If you want to use other names or emails in a specific project, just reconfigure without the --global option. The new settings will be saved in the .git/config file of the current project. ### Text Editor Set the default text editor used by Git. It might generally be Vi or Vim. If you have other preferences, such as VS Code, you can reset it: git config --global core.editor "code --wait" ### Diff Tool Another commonly used setting is which diff analysis tool to use when resolving merge conflicts. For example, to switch to vimdiff: git config --global merge.tool vimdiff Git can understand the output information from merge tools such as kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, and opendiff. Of course, you can also specify to use your own developed tool. Please refer to Chapter 7 for how to do that. ### Viewing Configuration Information To check existing configuration information, you can use the `git config --list` command: $ git config --list http.postbuffer=2M user.name= user.email=test@.com Sometimes you might see duplicate variable names, which means they come from different configuration files (e.g., /etc/gitconfig and ~/.gitconfig). However, Git ultimately uses the last one. We can also see these configurations in **~/.gitconfig** or **/etc/gitconfig**, as shown below: vim ~/.gitconfig The displayed content is as follows: postBuffer = sample text You can also directly look up the setting of a specific environment variable by appending its name, like this: $ git config user.name ### Generating SSH Key (Optional) If you need to perform Git operations via SSH, you can generate an SSH key and add it to your Git hosting service (such as GitHub, GitLab, etc.). ssh-keygen -t rsa -b 4096 -C "your.email@example.com" Follow the prompts to complete the generation process, then add the generated public key to the corresponding platform. ### Verifying Installation Run the following commands in the terminal or command line to ensure Git is correctly installed and configured: git --version git config --list
← Git WorkflowGit Tutorial β†’