Git Installation and Configuration
This chapter will detail how to install Git on different operating systems and perform basic configuration, allowing you to quickly start using Git.
Git Installation
Windows System Installation
Method 1: Official Installer
- Visit the Git official website
- Click "Download for Windows"
- Run the installer after downloading
- Follow the installation wizard to complete installation
Method 2: Using Package Managers
Installation Options Explanation
- Adjust PATH environment: Choose "Git from the command line and also from 3rd-party software"
- Choose HTTPS transport backend: Choose "Use the OpenSSL library"
- Configure line ending conversion: Choose "Checkout Windows-style, commit Unix-style line endings"
- Configure terminal emulator: Choose "Use Windows' default console window"
macOS System Installation
Method 1: Using Homebrew (Recommended)
Method 2: Using MacPorts
Method 3: Official Installer
- Visit the Git official website
- Download macOS version
- Run the .dmg file and follow prompts to install
Method 4: Xcode Command Line Tools
Linux System Installation
Ubuntu/Debian System
CentOS/RHEL/Fedora System
Arch Linux
Compile from Source
Git Basic Configuration
User Information Configuration
After installation, you first need to configure user information:
Configuration Levels
Git has three configuration levels:
Priority: local > global > system
Viewing Configuration
Editor Configuration
Diff Tool Configuration
Alias Configuration
Create aliases for commonly used commands:
Line Ending Configuration
Color Configuration
Push Configuration
Credential Configuration
SSH Key Configuration
Generating SSH Keys
Configuring SSH Keys
Testing SSH Connection
Configuration File Locations
Configuration File Paths
Editing Configuration Files Directly
Example .gitconfig file:
Proxy Configuration
HTTP/HTTPS Proxy
Domain-Specific Proxy
Common Configuration Issues
Issue 1: Chinese Filename Display
Issue 2: Line Ending Issues
Issue 3: Case Sensitivity
Issue 4: File Permission Issues
Verification Configuration
Create a test script to verify configuration:
Summary
Proper Git installation and configuration is the foundation for efficient Git usage:
Installation Key Points
- ✅ Choose installation method suitable for your operating system
- ✅ Verify that installation was successful
- ✅ Understand meaning of different installation options
Configuration Key Points
- ✅ Set username and email (required)
- ✅ Configure appropriate editor
- ✅ Set line ending handling strategy
- ✅ Create useful aliases
- ✅ Configure SSH keys
Best Practices
- 🔧 Use global configuration for general options
- 🔧 Set specific local configurations for different projects
- 🔧 Regularly backup configuration files
- 🔧 Understand configuration priority
After completing configuration, you can start using Git for version control. In the next chapter, we will learn Git's quick start guide.