
Getting Started with Git: Installation and First-Time Setup
Version control is the bedrock of modern software development, and Git is the undisputed industry standard. Whether you’re a solo developer tracking your project’s history or part of a large team collaborating on a complex application, mastering Git is a non-negotiable skill. The first step on that journey is a proper installation and a few crucial configuration tweaks.
This guide will walk you through installing Git on any major operating system and configuring it correctly so you can start versioning your projects with confidence.
How to Install Git: A Guide for Windows, macOS, and Linux
Getting Git onto your machine is a straightforward process, but the exact steps vary slightly depending on your operating system.
Installing Git on Windows
For Windows users, the most reliable method is to use the official Git for Windows installer.
- Navigate to the official Git website: git-scm.com/download/win.
- The download for the latest version should start automatically.
- Run the installer once it’s downloaded. You can safely accept most of the default settings, but pay attention to the option that allows you to choose your default editor. It’s often helpful to select a familiar editor like VS Code or Sublime Text if you have them installed.
The installer package includes both the core Git tools and Git Bash, a command-line environment that provides a Linux-like experience on Windows, which is incredibly useful for running Git commands.
Installing Git on macOS
macOS users have a few excellent options for installing Git.
Xcode Command Line Tools: The simplest way is often to just try running Git from the terminal. Open the Terminal app and type:
git --version
If you don’t have Git installed, macOS will prompt you to install the Xcode Command Line Tools. Agree to the installation, and Git will be installed as part of that package.
Using Homebrew: If you are a developer using macOS, you likely have or should have the package manager Homebrew. This is the recommended way to keep your Git installation up-to-date. Simply run:
bash
brew install git
Installing Git on Linux (Debian/Ubuntu)
On Debian-based distributions like Ubuntu, you can use the built-in Advanced Package Tool (APT).
- First, update your package index to ensure you get a recent version:
bash
sudo apt update
- Next, install Git using the package manager:
bash
sudo apt-get install git
- Verify the installation by checking the version:
bash
git --version
For other Linux distributions, you can use their native package managers, such as dnf
on Fedora (sudo dnf install git
).
Crucial First-Time Git Configuration
Once Git is installed, there are a few one-time configuration steps you must perform. This information is used to identify you as the author of your commits, which is essential for tracking changes and collaborating with others.
These settings are typically applied globally, meaning they will be used for every Git repository on your system.
1. Setting Your Identity: User Name and Email
Every commit you make in Git is stamped with your name and email address. It’s critical to set these values correctly.
Open your terminal or Git Bash and run the following commands, replacing the placeholder text with your actual information:
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
It’s highly recommended to use the same email address that you will use for services like GitHub or GitLab. This ensures your commits are correctly linked to your online profile.
2. Setting Your Default Branch Name (A Modern Best Practice)
Historically, the default branch in Git was named master
. In recent years, the industry has shifted towards using a more inclusive and descriptive term, main
. You can configure Git to use main
as the default for any new repository you create.
git config --global init.defaultBranch main
This is a simple change that aligns your workflow with modern development standards.
3. Choosing Your Default Text Editor
Git will sometimes need you to enter a message, such as when writing a detailed commit message. It does this by opening a text editor. You can configure Git to use your favorite editor.
For example, to set Visual Studio Code as your default editor, you would run:
git config --global core.editor "code --wait"
Check the documentation for your specific editor to find the correct configuration command.
4. Checking Your Configuration Settings
If you ever want to verify your configuration settings, you can use the git config --list
command to see all the settings that apply to your system.
git config --list
To check a specific value, such as your username, you can run:
git config user.name
This will return the name you configured earlier.
Next Steps: Enhancing Security with SSH
With your identity and preferences configured, you are ready to start using Git. As a next step, consider setting up SSH keys for authenticating with remote services like GitHub or GitLab. Using SSH is more secure than using passwords over HTTPS and provides a more seamless command-line experience.
By completing these installation and configuration steps, you’ve built a solid foundation for your development workflow. You’re now ready to create your first repository, make commits, and harness the full power of version control.
Source: https://linuxhandbook.com/courses/git-for-devops/configuring-git/