2025-02-06
编程
00
请注意,本文编写于 81 天前,最后修改于 80 天前,其中某些信息可能已经过时。

目录

在Ubuntu/Debian上安装Git
在CentOS上安装Git
在Windows上安装Git

git的各种安装指南

在Ubuntu/Debian上安装Git

  1. 更新软件包列表: 打开终端并运行以下命令来确保你的软件包列表是最新的:
bash
sudo apt update
  1. 安装Git: 使用APT包管理器来安装Git:
bash
sudo apt install git
  1. 验证安装: 安装完成后,可以通过以下命令验证Git是否安装成功,并查看其版本号:
bash
git --version
  1. 配置Git(可选但推荐): 为了更好地使用Git,建议设置你的用户名和邮箱:
bash
git config --global user.name "Your Name" git config --global user.email "you@example.com"

在CentOS上安装Git

  1. 更新软件包列表: 打开终端并运行以下命令来确保你的软件包列表是最新的:
bash
sudo yum update
  1. 安装Git: 使用YUM包管理器来安装Git:
  • 对于CentOS 8及以上版本:
bash
sudo yum install git
  • 对于CentOS 7及以下版本,你可能需要先启用EPEL(Extra Packages for Enterprise Linux)仓库:
bash
sudo yum install epel-release sudo yum install git
  1. 验证安装: 安装完成后,可以通过以下命令验证Git是否安装成功,并查看其版本号:
bash
git --version
  1. 配置Git(可选但推荐): 为了更好地使用Git,建议设置你的用户名和邮箱:
bash
git config --global user.name "Your Name" git config --global user.email "you@example.com"

在Windows上安装Git

  1. 下载Git for Windows: 访问Git官网下载适用于Windows的Git安装程序。

  2. 运行安装程序: 下载完成后,双击运行安装程序。按照安装向导的提示进行操作。你可以选择默认设置,或者根据需要自定义安装路径和其他选项。

  3. 选择安装路径: 在“Select Destination Location”页面,默认路径通常是C:\Program Files\Git,你可以根据需要更改安装路径。

  4. 选择组件: 在“Select Components”页面,你可以选择安装哪些组件。默认设置通常已经足够,但你可以根据需求进行调整。例如,可以勾选“On the Desktop”以便在桌面上创建快捷方式。

  5. 选择开始菜单文件夹: 在“Choose Start Menu Folder”页面,选择一个文件夹来放置Git的快捷方式。默认设置通常已经合适。

  6. 选择默认编辑器: 在“Choose the default editor used by Git”页面,选择你希望用作Git默认文本编辑器的工具。常见的选择包括Vim、VS Code等。如果你没有特别偏好,可以选择默认的Vim或Notepad++。

  7. 调整环境变量: 在“Adjusting your PATH environment”页面,选择如何将Git添加到系统的PATH环境变量中:

  • Use Git from Git Bash only:仅在Git Bash中使用Git命令。
  • Use Git from the Windows Command Prompt:允许在Windows命令提示符中使用Git命令。
  • Use Git and optional Unix tools from the Windows Command Prompt:不仅可以在命令提示符中使用Git命令,还可以使用一些Unix工具。
  1. 选择HTTPS传输后端: 在“Choosing the SSH executable”页面,选择SSH客户端。通常情况下,默认选项“Use OpenSSH”是合适的。

  2. 配置行尾转换: 在“Configuring the line ending conversions”页面,选择如何处理行尾字符(Line Endings):

  • Checkout as-is, commit Unix-style line endings:检出时保持原样,提交时使用Unix风格的换行符。
  • Checkout Windows-style, commit Unix-style line endings:检出时使用Windows风格的换行符,提交时使用Unix风格的换行符。
  • Checkout as-is, commit as-is:检出和提交时都保持原样。
  1. 配置终端模拟器: 在“Configuring the terminal emulator to use with Git Bash”页面,选择终端模拟器:
  • Use MinTTY (the default terminal of MSYS2):使用MinTTY作为终端模拟器。
  • Use Windows' default console window:使用Windows默认的控制台窗口。
  1. 额外选项
  • 在“Configuring extra options”页面,可以根据需要选择其他选项,如启用文件系统缓存、启用符号链接等。
  1. 完成安装: 安装完成后,可以在开始菜单中找到“Git Bash”或“Git CMD”,这些是Git在Windows上的命令行工具。

  2. 验证安装: 打开Git Bash或Git CMD窗口,并输入以下命令以验证Git是否安装成功,并查看其版本号:

bash
git --version
  1. 配置Git(可选但推荐): 为了更好地使用Git,建议设置你的用户名和邮箱:
bash
git config --global user.name "Your Name" git config --global user.email "you@example.com"
  1. 验证配置
  • 你可以通过以下命令查看当前的全局Git配置:
bash
git config --list

文章如有错误,还望留言指正

参考资料 来自ai生成