Installing Git
Install Git on macOS, Linux, and Windows, then configure your identity, editor, and default branch for a clean first setup.
Why Installation and Setup Matter
Installing Git is quick, but good initial configuration saves time every day. Your name and email appear in commits, your editor opens when Git needs input, and your default branch name affects new repositories.
A clean setup helps you avoid confusing commit authors, awkward editor prompts, and inconsistent branch names across projects.
Tip: Configure Git once on your machine before starting real work. It prevents small problems from becoming repeated annoyances.
Installing Git on macOS
On macOS, the easiest path is often to install the Xcode Command Line Tools. If Git is missing, macOS may prompt you automatically when you run git.
Check first:
git --version
If Git is not installed, you can use:
xcode-select --install
If you use Homebrew, you can also install Git with:
brew install git
After installation, verify it:
git --version
Installing Git on Linux
Git is available through most Linux package managers.
Ubuntu or Debian
sudo apt update
sudo apt install git -y
Fedora
sudo dnf install git -y
CentOS or RHEL
sudo yum install git -y
Arch Linux
sudo pacman -S git
Then confirm the installation:
git --version
Installing Git on Windows
On Windows, the most common option is Git for Windows, which includes Git Bash and useful command-line tools.
- Download Git for Windows from the official installer.
- Run the installer.
- Accept the defaults unless your team has specific requirements.
- Open Git Bash or Command Prompt and verify:
git --version
Git Bash is especially helpful because many tutorials and DevOps commands assume a Unix-like shell experience.
Note: If you work with VS Code, Git for Windows integrates well with its built-in terminal and source control features.
Configuring Your Identity
Git needs to know who you are so commits can record an author.
Set your global name:
git config --global user.name "Vish Patel"
Set your global email:
git config --global user.email "vish@example.com"
These settings apply to all repositories on your machine unless a repository overrides them.
Check your current config:
git config --global --list
Why This Matters
If your name or email is wrong, your commits may appear under the wrong identity on Git hosting platforms. That can make collaboration and auditing harder.
Setting Your Default Editor
Git sometimes opens an editor for commit messages, merge messages, or rebase instructions. Setting your preferred editor makes those workflows smoother.
For VS Code:
git config --global core.editor "code --wait"
For Vim:
git config --global core.editor "vim"
For Nano:
git config --global core.editor "nano"
The --wait flag is important for VS Code because Git must pause until you finish editing.
Choosing a Default Branch Name
Many teams now use main instead of master as the default branch name.
Configure new repositories to start with main:
git config --global init.defaultBranch main
Now when you run git init, the initial branch will be main.
Verify it:
git config --global init.defaultBranch
Useful Optional Setup
Here are a few optional settings beginners often appreciate.
Show Helpful Colors
git config --global color.ui auto
Cache Credentials Temporarily on macOS or Linux
git config --global credential.helper cache
Use the Windows Credential Manager
On Windows, Git for Windows can help manage stored credentials depending on your install options.
Tip: Be careful storing credentials directly in files. Use secure credential helpers or SSH keys when possible.
Local vs Global Configuration
Git configuration can exist at different levels:
- System: applies to every user on a machine
- Global: applies to your user account
- Local: applies only inside one repository
For example, if one work project needs a company email, you can override it inside that repository:
git config user.email "vish@company.com"
To inspect all effective settings and where they came from:
git config --list --show-origin
A Good First-Time Setup Checklist
A practical first-time setup often looks like this:
git config --global user.name "Vish Patel"
git config --global user.email "vish@example.com"
git config --global core.editor "code --wait"
git config --global init.defaultBranch main
git config --global color.ui auto
Then verify:
git config --global --list
What You Should Remember
Installing Git is easy, but the important part is configuration. Set your identity, editor, and default branch right away. That gives you cleaner commits, better compatibility with team workflows, and fewer surprises when Git opens an editor or creates a new repository.
Once Git is installed and configured, you are ready to create or clone repositories and start tracking real work.
Test Your Understanding
Let's see how well you understood the concepts! These exercises will help reinforce what you just learned.
Exercise 1: Verifying installation
Scenario: You are on a new macOS machine and want to confirm whether Git is already available before installing anything.
Question: Which command from the tutorial should you run first?
Exercise 1: Verifying installation
Choose the command that checks whether Git is already installed.
Exercise 2: Choosing an editor
Question: Why does the tutorial recommend git config --global core.editor "code --wait" when using VS Code?
Exercise 2: Choosing an editor
Identify why the --wait flag matters when configuring VS Code as the Git editor.
Exercise 3: Global vs local identity
Scenario: Your personal machine uses vish@example.com globally, but one company repository must use vish@company.com for commits.
Question: Which approach matches the tutorial?
Exercise 3: Global vs local identity
Choose the correct way to override commit identity for just one repository.