DevOpsLesson
DevOpsLesson

Free, comprehensive DevOps tutorials and learning roadmaps. Master Docker, Kubernetes, CI/CD, and more.

Stay Updated

Get notified about new tutorials and features.

Tutorials

  • What is DevOps?
  • Docker Tutorial
  • Terraform Tutorial
  • CI/CD Pipeline
  • All Tutorials

Roadmaps

  • DevOps Engineer
  • Cloud Engineer
  • SRE Path
  • All Roadmaps

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service

© 2026 DevOpsLesson. All rights reserved.

DOCKERKUBERNETESTERRAFORMAWSCI/CDLINUXGITDEVOPS ROADMAPCLOUD ROADMAPSRE ROADMAPGIT CHEATSHEETDOCKER CHEATSHEETK8S CHEATSHEETTF CHEATSHEETLINUX CHEATSHEETDOCKERFILE LINTERYAML VALIDATORCRON PARSERREGEX TESTER

Git Tutorial

Introduction to Git
Installing Git
Git Basics
Git Branching
Git Merging
Git Rebasing
Git Remote
Git Stash
Undoing Changes in Git
Git Tagging
GitHub Workflow with Git
Advanced Git
Git Hooks
Git Workflows
Git Aliases and Configuration
Git Submodules
Git Commit Messages

Installing Git

PreviousPrev
Next

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.

  1. Download Git for Windows from the official installer.
  2. Run the installer.
  3. Accept the defaults unless your team has specific requirements.
  4. 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

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

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

Exercise 3: Global vs local identity

Choose the correct way to override commit identity for just one repository.

PreviousPrev
Next

Continue Learning

Introduction to Git

Learn what Git is, why version control matters, and how distributed version control helps teams work safely and efficiently.

12 min·Easy

Git Basics

Learn the everyday Git workflow with init, clone, status, add, commit, log, and diff using practical beginner-friendly examples.

15 min·Easy

Git Branching

Understand Git branches, HEAD, switching branches, deleting branches, and detached HEAD with practical beginner examples.

18 min·Easy

Explore Related Topics

CI

CI/CD Tutorials

Trigger automated pipelines from Git workflows

Li

Linux Tutorials

Use Git effectively on the Linux command line

On This Page

Why Installation and Setup MatterInstalling Git on macOSInstalling Git on LinuxUbuntu or DebianFedoraCentOS or RHELArch LinuxInstalling Git on WindowsConfiguring Your IdentityWhy This MattersSetting Your Default EditorChoosing a Default Branch NameUseful Optional SetupShow Helpful ColorsCache Credentials Temporarily on macOS or LinuxUse the Windows Credential ManagerLocal vs Global ConfigurationA Good First-Time Setup ChecklistWhat You Should RememberTest Your UnderstandingExercise 1: Verifying installationExercise 2: Choosing an editorExercise 3: Global vs local identity