Multi-Platform Installation
Git is designed to be portable across all POSIX-compliant systems and Windows. In academic and professional settings, you will likely encounter a heterogeneous environment where developers use different operating systems.
Installation via Package Managers
The preferred method for installing Git is through the system’s native package manager to ensure compatibility and easy updates.
Linux and BSD
On Debian-based systems (Ubuntu, Mint):
sudo apt update && sudo apt install git
On Red Hat-based systems (Fedora, RHEL):
sudo dnf install git
On Arch Linux:
sudo pacman -S git
On FreeBSD:
pkg install git
macOS
While macOS comes with a version of Git installed via Xcode Command Line Tools, many developers prefer the more up-to-date version from Homebrew:
brew install git
Windows
For Windows, Git for Windows (also known as Git Bash) is the standard. It provides a BASH emulation environment which is critical for maintaining script compatibility across teams. You can install it via Winget:
winget install --id Git.Git -e --source winget
Initial Configuration: The Identity
Git records the identity of the author for every commit. This is not for authentication, but for accountability and metadata. These settings are stored in the ~/.gitconfig file (or %USERPROFILE%\.gitconfig on Windows).
git config --global user.name "Leonardo da Vinci"
git config --global user.email "leo@renaissance.org"
The --global flag ensures that these settings are applied to every repository on your machine. For project-specific identities (e.g., using a work email for a specific repo), you can omit the flag while inside that repository.
The Problem of Line Endings: CRLF vs. LF
One of the most common issues in cross-platform development is how different operating systems handle the end of a line in a text file.
- Windows: Uses Carriage Return (CR) and Line Feed (LF) together (
\r\n). - Linux/macOS/BSD: Uses only Line Feed (LF) (
\n).
If not managed, Git will see the change in line endings as a change to the entire file, leading to “merge hell.”
Configuration for Windows Users
You should configure Git to convert LF to CRLF when checking out code, and convert CRLF back to LF when committing:
git config --global core.autocrlf true
Configuration for Linux/macOS/BSD Users
You should ensure that Git only converts CRLF to LF on commit, but doesn’t do anything on checkout:
git config --global core.autocrlf input
Configuring the Default Editor
By default, Git may fall back to vi or vim. If you are not comfortable with modal editors, you should change it to a simpler one like nano or a code editor like VS Code:
# To use Nano
git config --global core.editor "nano"
# To use VS Code
git config --global core.editor "code --wait"
Verification of Configuration
# Command to list all active configurations
git config Identity and Security
While user.name and user.email identify you in the history, they do not verify your identity. In a DevOps pipeline, you will typically use SSH Keys or Personal Access Tokens (PAT) for authentication with remotes like GitHub or GitLab.
Generating an SSH Key
If you prefer SSH for secure communication without typing passwords:
ssh-keygen -t ed25519 -C "your_email@example.com"
This generates a public/private key pair. You would then provide the public key (~/.ssh/id_ed25519.pub) to your Git hosting provider.
Why is core.autocrlf important in a team with both Windows and Mac users?
Checking your Environment
Waiting for signal...