如何安装 Git (带翻译)

本文使用 Windows 和 Linux 进行演示,仅限参考,问题请在评论提出

目录

一、Github

二、Git

(一)Linux 安装

(二)Windows 安装


一、Github

GitHub 是一个面向开源及私有软件项目的托管平台,因为只支持 Git 作为唯一的版本库格式进行托管,故名 GitHub 。作为开源代码库以及版本控制系统, GitHub 拥有超过900万开发者用户。随着越来越多的应用程序转移到了云上, GitHub 已经成为了管理软件开发以及发现已有代码的首选方法。是目前全球最大的代码开源平台。

百度百科

二、Git

Git(读音为/gɪt/)是一个开源的分布式版本控制系统,可以有效、高速地处理从很小到非常大的项目版本管理。也是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码的版本控制软件。

百度百科

(一) Linux 安装

1. Debian 系

# 使用 APT 包管理器
sudo apt install git

2. Red Hat 系

# 使用 DNF 包管理器
sudo dnf install git

# 使用 YUM 包管理器
sudo yum install git

3. 其他

参考 Download for Linux and Unix

(二) Windows 安装

1. 进入官网 Git (git-scm.com) ,点击 Download for Windows 进入页面

2. 点击 Click here to download 下载

3. 打开安装包,点击 Next 下一步

4. 选择安装目录,点击 Next 下一步

5. 设置安装选项,点击 Next 下一步

  • Additional icons (One the Desktop)
    创建桌面快捷方式
  • Windows Explorer integration
    右键菜单
  • Git LFS (Large File Support)
    Git 对大文件的支持
  • Associate .git* configuration files with the default text editor
    将 .git* 配置文件与默认文本编辑器相关联
  • Associate .sh files to be run with Bash
    使用 Bash 运行 .sh 文件
  • Check daily for Git for Windows updates
    每日检查更新
  • (NEW!) Add a Git Bash Profile to Windows Terminal
    (新的!)在 Windows Terminal 中添加 Git Bash 配置文件(已安装 Windows Terminal 可勾上)

6. 输入开始菜单文件夹名,点击 Next 下一步(默认即可)

7. 选择默认文本编辑器,选择自己常用的即可,点击 Next 下一步

8. 设置新仓库初始化分支名称,点击 Next 下一步

  • Let Git decide: Let Git use it default branch name (currently: “master”) for the initial branch in newly created repositories. The Git project intends to change this default to a more inclusive name in the near future.
    让 Git 决定:新建仓库的初始化分支使用默认分支名称。(当前为:“master”) Git 项目打算在不久的将来将此默认名称更改为更具包容性的名称。
  • Override the default branch name for new repositories: NEW! Many teams already renamed their default branches; common choices are “main”, “trunk” and “development”. Specify the name “git init” should use for the initial branch:
    覆盖新仓库的默认分支名称:新的!很多团队已经重命名了他们的默认分支,常见的选择有”main”、”trunk”和”development”。指定”git init”时创建的初始化分支名称:

9. 配置PATH环境,选 Git from the command line and also from 3rd-party software ,点击 Next 下一步

  • Use Git from Git Bash only: This is the most cautious choice as your PATH will not be modified at all. You will only be able to use the Git command line tools from Git Bash.
    仅在 Git Bash 中使用 Git:这是最谨慎的选择,因为您的 PATH 压根不会被修改。您将只能在 Git Bash 中使用 Git 命令行工具。
  • Git from the command line and also from 3rd-party software: (Recommended) This option adds only some minimal Git wrapper to your PATH to avoid cluttering your environment with optional Unix tools. You will be able to use Git from Git Bash, the Command Prompt and the Windows PowerShell as well as any third-party software looking for Git in PATH.
    在命令行和第三方软件中使用 Git :(推荐)此选项仅向您的 PATH 添加一些最小的 Git 包装器,以避免使用可选的 Unix 工具使您的环境混乱。 您将能够在 Git Bash、命令提示符和 Windows PowerShell 中使用 Git (但仅能在 Git Bash 中使用Unix工具),以及在 PATH 中查找 Git 的任何第三方软件。
  • Use Git and optional Unix tools from the Command Prompt: Both Git and the optional Unix tools will be added to your Path. Warring: This will override Windows tools like “find” and “sort”. Only use this option if you understand the implications.
    在命令提示符中使用 Git 和可选的 Unix 工具:Git 和可选的 Unix 工具都将添加到您的PATH中。 注意:这将覆盖 Windows 工具,如”find”和”sort”。 仅当您了解其含义并知道其后果时才使用此选项。

10. 选择 SSH 可执行文件,点击 Next 下一步

  • Use bundled OpenSSH: This uses ssh.exe that comes with Git.
    使用捆绑的 OpenSSH:使用 Git 附带的 ssh.exe。
  • Use external OpenSSH: NEW! This uses an external ssh.exe. Git will not install its own OpenSSH (and related) binaries but use them as found on the PATH.
    使用外部的 OpenSSH:新的!使用外部 ssh.exe。Git 将不会安装自己的 OpenSSH (和相关的)二进制文件,而是使用在 PATH 中找到的。

11. 选择 HTTPS 传输后端,选 Use the OpenSSL library ,点击 Next 下一步

  • Use the OpenSSL library: Server certificates will be validated using the ca-bundle.crt file.
    使用 OpenSSL 库:将使用 ca-bundle.crt 文件验证服务器证书。
  • Use the native Windows Secure Channel library: Server certifivates will be vaildated using Windows Certificate Stores. This option alse allows you to use your company’s internal Root CA certificates distributed e.g. via Active Directory Domain Services.
    使用本机 Windows 安全通道库:服务器证书将使用 Windows 证书存储进行验证。 此选项还允许您使用公司内部分发的根 CA 证书,例如 通过 Active Directory 域服务。

12. 配置行尾转换,选 Checkout Windows-style, commit Unix-style line endings ,点击 Next 下一步

  • Checkout Windows-style, commit Unix-style line endings: Git will convert LF to CRLF when checking out text files. When committing text files, CRLF wil be converted to LF. For cross-platform projects, this is the recommended setting on Windows (“core.autocrlf” is set to “true”).
    checkout 时使用 Windows 风格,commit 时使用 Unix 风格的行尾:Git 将在 checkout 文本文件时将 LF 转换为 CRLF 。 commit 文本文件时,CRLF 将转换为 LF 。 对于跨平台项目,这是 Windows 上的推荐设置。(”core.autocrlf”将设置为”true”)
  • Checkout as-is, commit Unix-style line endings: Git will not perform any conversion when checking out text files, CRLF will be converted to LF. For cross-platform projects, this is the recommended setting on Unix (“core.autocrlf” is set to “input”).
    按原样 checkout ,commit 时使用 Unix 风格的行尾:Git 在checkout文本文件时不会执行任何转换,CRLF 将被转换为 LF。 对于跨平台项目,这是 Unix 上的推荐设置。(”core.autocrlf”设置为”input”)
  • Checkout as-is, commit as-is: Git will not perform any conversions when checking out or committing text file. Choosing this option is not recommand for cross-platform projects (“core.autocrlf” is set to “false”).
    按原样 checkout ,按原样 commit :当 checkout 或 commit 文本文件时,Git 不会执行任何转换。 不建议跨平台项目选择此选项。(”core.autocrlf”设置为”false”)

13. 配置 Git Bash 使用的终端模拟器,选 Use MinTTY (the default terminal of MSYS2) ,点击 Next 下一步

  • Use MinTTY (the defult terminal of MSYS2): Git Bash will use MinTTY as terminal emulator, which sports a resizable window, non-rectangular selections and a Unicode font. Windows console programs (such as interactive Python) must be launched via ‘winpty’ to work in MinTTY.
    使用 MinTTY(MSYS2 的默认终端):Git Bash 将使用 MinTTY 作为终端模拟器,它具有可调整大小的窗口、非矩形选择和 Unicode 字体。 Windows 控制台程序(例如交互式 Python)必须通过 “winpty” 启动才能在 MinTTY 中运行。
  • Use Windows’ default console window: Git will use the default console window of Windows (“cmd.exe”), which works well with Win32 console programs such as interactive Python or node.js, but has a very limited default scroll-back, needs to be configured to use a Unicode font in order to display non-ASCII characters correctly, and prior to Windows 10 its window was not freely resizable and it only allowed rectangular text selections.
    使用 Windows 的默认控制台窗口:Git 将使用 Windows 的默认控制台窗口(”cmd.exe”),它适用于 Win32 控制台程序,例如交互式 Python 或 node.js,但具有非常有限的默认回滚, 需要配置为使用 Unicode 字体才能正确显示非 ASCII 字符,在 Windows 10 之前,它的窗口不能自由调整大小,并且只允许矩形文本选择。

14. 选择 “git pull” 的默认行为,选 Default (fast-forward or merge) ,点击 Next 下一步

  • Default (fast-forward or merge): This is the standard behavior of ‘git pull’: fast-forward the current branch to the fetched branch when possible, otherwise create a merge commit.
    默认(快进或合并):这是 ‘git pull’ 的标准行为:在可能的情况下将当前分支快进到提取的分支,否则创建合并提交。
  • Rebase: Rebase the current branch onto the fetched branch. If there are no local commits to rebase, this is equivalent to a fast-forward.
    重设基线:将当前分支 rebase 到获取的分支上。 如果没有本地 commit 可以 rebase ,这相当于快进。
  • Only ever fast-forward: Fast-forward to the fetched branch. Fail if that is not possible.
    只快进:快进到获取的分支。 如果不可能,则失败。

15. 选择凭证助手,选 Git Credential Manager core ,点击 Next 下一步

  • Git Credential Manager: Use the cross-platform Git Credential Manager. See more information about the future of Git Credential Manager here.
    Git 凭证管理器:使用跨平台的 Git 凭证管理器。 在此查看有关 Git 凭证管理器未来的更多信息。
  • None: Do not use a credential helper.
    无:不使用凭证助手。

16. 配置额外选项,点击 Next 下一步

  • Enable file system caching: File system data will be read in bulk and cached in memory for certain operations (“core.fscache” is set to “true”). This provides a significant performance boost.
    启用文件系统缓存:文件系统数据将被批量读取并缓存在内存中以进行某些操作(”core.fscache”将设置为”true”)。 这能显著提升性能。
  • Enable symbolic links: Enable symbolic links (requires the SeCreateSymbolicLink permission). Please note that existing repositories are unaffected by this setting.
    启用符号链接:启用符号链接(需要 SeCreateSymbolicLink 权限)。 请注意,现有存储库不受此设置的影响。

17. 配置实验选项,点击 Install 安装

  • Enable experimental support for pseudo consoles: (NEW!) This allows running native console programs like Node or Python in a Git Bash windows without using winpty, but it still has known bugs.
    启用对伪控制台的实验性支持:(新的!)允许在 Git Bash 窗口中运行本地控制台程序,如 Node 或 Python,而无需使用 winpty,但它仍然存在已知错误。
  • Enable experimental build-in file system monitor: (NEW!) Automatically run a build-in file system watcher, to speed up common operations such as ‘git status’, ‘git add’, ‘git commit’, etc in worktress containing many files.
    启用实验性内置文件系统监视器:(新的!)自动运行内置文件系统监视器,以加快包含许多工作台中的“git status”、“git add”、“git commit”等常见操作 文件。

18. 安装完成,点击 Finish 完成

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注