[Git Basics] How to Install and Configure Git Initially: What You Need to Know

VnnTools

Welcome to the world of modern programming! If there is one tool considered indispensable for every developer, from fresh graduates to engineers at major tech companies, it is Git.

How to Install and Configure Git: What You Need to Know

This article will walk you through the two most important steps to start your journey with Git: Installation and Initial Configuration. Don’t worry if you’re a beginner—we’ll go step by step, nice and easy!

🚀 Step 1: Install Git on Your Operating System

The process of installing Git is very simple and varies slightly depending on your operating system.

On Windows

The easiest way to install Git on Windows is to use the official Git for Windows installer.

  1. Download the Git installer: Go to the official website: https://git-scm.com/download/win. Your browser will automatically download the appropriate installer for your Windows version (32-bit or 64-bit).
  2. Run the installer: Open the .exe file you just downloaded.
  3. Follow the installation steps: You’ll see many configuration screens. For beginners, you can safely leave the default settings and click "Next" until the installation is complete.

Important note: At the "Choosing the default editor used by Git" step, if you’re familiar with a code editor like Visual Studio Code, Sublime Text, or Notepad++, select it from the list. Otherwise, leave it as Vim (but be prepared to learn how to use it!).

On macOS

On macOS, you have two common options:

  1. Using Homebrew (Recommended): If you’re a Mac developer, you probably already have or will install Homebrew. It’s a great package manager. Open Terminal and run:
brew install git
  1. Using Xcode Command Line Tools: If you have Xcode installed, Git may already be installed. If not, just open Terminal and type:
git --version
  • If Git is not installed, a window will pop up asking you to install the "Command Line Developer Tools." Click "Install" and follow the instructions.

On Linux (Ubuntu/Debian)

On Debian/Ubuntu-based Linux distributions, installing Git is extremely simple.

  • Open Terminal and run the following commands:
sudo apt update
sudo apt install git

✅ Verify Successful Installation

After installation is complete on any operating system, open Terminal (or Git Bash on Windows) and type:

git --version

If you see a line like git version 2.45.1, congratulations! You have successfully installed Git.

⚙️ Step 2: Initial Configuration – "Declare Your Identity"

This is a crucial step that many beginners often overlook. Before you create your first project history, you need to tell Git who you are. Every time you save a change (a "commit"), Git attaches this information. It’s like signing your name to your work.

You only need to do this once on your computer. Open Terminal (or Git Bash) and run the following two commands. Replace "Your Name" and "youremail@example.com" with your real name and email.

  1. Configure your username:
git config --global user.name "Nguyen Van A"
  1. Configure your email address:
git config --global user.email "nguyenvana@email.com"

The --global flag means you’re setting this information for all Git projects on your computer.

Tip: Use the same email you use for GitHub, GitLab, or Bitbucket. This will help link your commits to your account on those platforms automatically.

To check the information you just configured, use:

git config --list

You’ll see lines like user.name=... and user.email=... in the list.

✨ Other Useful Configurations (Recommended)

To improve your Git experience, consider a few more configurations:

1. Set the Default Code Editor

As mentioned, Git will open a text editor when you run commands like commit without providing a message directly. If you don’t like Vim, you can change it. For example, to set Visual Studio Code as the default editor:

git config --global core.editor "code --wait"

2. Set the Default Branch Name to "main"

Previously, Git’s default branch was called "master." However, the community is moving towards using "main" for greater neutrality. This is a good practice to follow.

git config --global init.defaultBranch main

This command ensures that whenever you create a new repository with git init, the main branch will automatically be named main.

🗺️ What’s Next?

Great! Your computer is now fully ready to work with Git. You’ve overcome the first and most important hurdle.

Your journey with Git is just beginning. The next steps will be:

  • Learn basic Git commands: git init, git add, git commit, git status, git log.
  • Create a GitHub (or GitLab) account: This is where you’ll store your projects online, share them with others, and contribute to open source projects.
  • Learn how to connect your local repository to a remote one: Use commands like git remote, git push, and git pull.

Congratulations on completing the installation and configuration of Git. This is a foundational skill that will serve you throughout your programming career. Start building awesome projects and don’t forget to commit often!

Wishing you clean commits and a wonderful project history!

Related Posts

[Git Basics] What is Git? Discover the Role of Git in Programming

Git is an extremely popular version control system. This article explains what Git is, why every developer should know it, and the steps to get started.

[Git Basics] Git Repository: The Essential Foundation for Source Code Management

The Git Repository is the core foundation of Git. Discover how a Git Repository helps you manage, track history, and collaborate effectively in your programming projects.

React Component Lifecycle: Essential Knowledge You Need to Master

React Component Lifecycle is fundamental knowledge you must understand. Learn how components are created, updated, and destroyed to optimize performance and avoid common pitfalls in React applications.

Optimize CSS to Speed Up Your Website: A Complete A-Z Guide

Optimizing CSS for your website helps pages load faster, improves SEO, and enhances user experience. Discover compression techniques, merging, removing unused CSS, and much more!