Getting Started with Git
Now that you understand what version control is and why Git is a popular choice, it's time to get Git up and running on your system and make your first configurations. This page will guide you through the initial steps.
1. Installing Git
Git is cross-platform and can be installed on Linux, macOS, and Windows.
- Linux: You can usually install Git through your distribution's package manager. For Debian/Ubuntu:
For Fedora:sudo apt-get update sudo apt-get install git
sudo dnf install git
- macOS: The easiest way to install Git on a Mac is to install the Xcode Command Line Tools. If you try to run
git
from the terminal for the first time, it will prompt you to install them. Alternatively, you can download an installer from the official Git website or install it via Homebrew (brew install git
). - Windows: Download the official Git for Windows installer from git-scm.com/download/win. Run the installer and follow the prompts. It includes Git BASH, a command-line tool that emulates a Bash shell, and also integrates with the standard Command Prompt and PowerShell.
After installation, you can verify it by opening your terminal or command prompt and typing: git --version
. This should display the installed Git version.
2. Initial Configuration
Once Git is installed, there are a few essential one-time configurations you should perform. Most importantly, you need to tell Git your name and email address. This information is embedded into each commit you make.
git config --global user.name "Your Name"
git config --global user.email "youremail@example.com"
Replace "Your Name" and "youremail@example.com" with your actual name and email. The --global
option means these settings will apply to all Git repositories you work with on your system. If you need different settings for a specific project, you can omit --global
when running these commands inside that project's directory.
Other Useful Configurations:
- Default Editor: Git uses your system's default editor for commit messages if not specified. You can set your preferred editor:
git config --global core.editor "nano" # or vim, emacs, code --wait, etc.
- Default Branch Name: Historically, the default branch name was `master`. Many communities are now moving to `main`. You can set your default branch name for new repositories (requires Git 2.28 or newer):
git config --global init.defaultBranch main
- Checking Your Settings: You can view all your global settings by typing:
git config --list --global
3. Getting Help
If you ever need help with a Git command, there are several ways to access the documentation:
git help <command>
(e.g.,git help config
)git <command> --help
(e.g.,git config --help
)man git-<command>
(e.g.,man git-config
) on Linux/macOS
This will usually open the relevant man page or documentation in your web browser.
4. Creating Your First Repository
You can start using Git in two main ways:
- Initializing a repository in an existing project:
Navigate to your project's root directory in the terminal and run:
This creates a new subdirectory namedgit init
.git
that contains all your necessary repository files – a Git repository skeleton. At this point, nothing in your project is tracked yet. You'll learn how to stage and commit files in the next section. - Cloning an existing repository:
If you want to get a copy of an existing Git repository — for example, a project you want to contribute to — the command you need is
git clone
. For example:
This creates a directory named "git", initializes agit clone https://github.com/git/git.git
.git
directory inside it, pulls down all the data for that repository, and checks out a working copy of the latest version. Effective repository management is crucial for complex project setups, similar to how one might manage configurations when mastering containerization with Docker and Kubernetes.
Congratulations! You've installed and configured Git, and you're ready to start using it. The next step is to learn some basic Git commands to track your project files.
Next: Basic Git Commands ➡️