← Back to list

Git: The Complete Beginner’s Guide to Version Control

Learn what Git is, how to install it on any platform, and how to use it confidently — even if you’ve never touched a terminal before.

Manjunatha K.V · 2026-06-05 15:13 · 0 claps · 12.9 min read
#git
Open on Medium ↗
Wiki topics: 🔓 · Open Source

Git: The Complete Beginner’s Guide to Version Control

Learn what Git is, how to install it on any platform, and how to use it confidently — even if you’ve never touched a terminal before.

Introduction

Imagine you’re writing a 50-page report. Halfway through, you make a big change — and then realize the earlier version was better. If you didn’t save a backup, that earlier version is gone forever.

Now imagine you’re writing code. Same problem, but 10 times worse.

That’s exactly the problem Git solves.

Git is a version control system — a tool that tracks every change you make to your code over time. It lets you save snapshots of your work, go back to any previous version, collaborate with teammates without overwriting each other’s code, and manage multiple versions of a project simultaneously.

If you’re learning to code, Git is not optional. It’s one of the most important tools in a developer’s toolkit — and every employer expects you to know it.

This guide will walk you through everything from scratch: what Git is, how to install it, how to configure it, and how to use it in real projects. No experience required.

What Is Git? (And Why Should You Care?)

Git was created in 2005 by Linus Torvalds — the same person who created the Linux operating system. He built Git to manage the Linux kernel’s source code, which was being contributed to by thousands of developers around the world.

Today, Git is used by virtually every software team on the planet.

Here’s what Git does for you:

  • Tracks changes — Every edit you make is recorded with a timestamp and message
  • Lets you go back — Made a mistake? Roll back to any previous state of your project
  • Enables collaboration — Multiple people can work on the same project without conflicts
  • Supports branching — Work on a new feature without breaking the main project
  • Backs up your work — Push your code to a remote server like GitHub for safekeeping

Git vs. GitHub — What’s the Difference?

This is one of the most common points of confusion for beginners.

  • Git is the tool installed on your computer that tracks changes locally
  • GitHub is a website where you can store and share your Git repositories online

Think of it this way: Git is like Microsoft Word’s “Track Changes” feature. GitHub is like Google Drive — a place to store and share your documents.

You can use Git without GitHub. But most developers use both together.

Part 1: Installing Git on macOS

Check If Git Is Already Installed

Many Macs come with Git pre-installed. Before downloading anything, open Terminal and type:

git --version

If you see something like git version 2.39.0, Git is already installed and you can skip to Part 4: Initial Configuration.

If you see an error or get a prompt to install Xcode Command Line Tools, follow the steps below.

Option 1: Install via Xcode Command Line Tools (Easiest)

  1. Open Terminal (press Cmd + Space, type "Terminal", hit Enter)
  2. Run the following command:
xcode-select --install
  1. A dialog box will appear asking if you want to install the Command Line Tools. Click Install.
  2. Wait for the installation to complete (it may take a few minutes).
  3. Verify the installation:
git --version

Option 2: Install via Homebrew (Recommended for Developers)

Homebrew is a package manager for macOS that makes installing developer tools easy. If you don’t have it yet, this is a great time to set it up.

Step 1: Install Homebrew

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Step 2: Install Git

brew install git

Step 3: Verify

git --version

Why use Homebrew? It gives you the latest version of Git and makes future updates easy with just brew upgrade git.

Option 3: Download the Installer

  1. Go to **https://git-scm.com/download/mac**
  2. Download the latest .pkg installer
  3. Open the file and follow the installation wizard
  4. Verify in Terminal: git --version

Common macOS Issues

Problem: *git command not found after installation* Fix: Close Terminal completely and reopen it. If still not working, check that Git's path is in your shell profile:

echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

Problem: Prompted to install Xcode every time you run git Fix: Run xcode-select --install and complete the full installation.

Part 2: Installing Git on Windows

Step 1: Download Git for Windows

  1. Open your browser and go to **https://git-scm.com/download/win**
  2. The download will start automatically for the 64-bit version
  3. Save the .exe installer to your Downloads folder

Step 2: Run the Installer

Double-click the downloaded file and follow the setup wizard. Here are the key screens to pay attention to:

Select Components screen: Leave the defaults checked. Make sure Git Bash and Git GUI are selected.

Choosing the default editor: By default, Git uses Vim — which is confusing for beginners. Instead, select Visual Studio Code (or Notepad++) from the dropdown.

Adjusting your PATH environment: Select “Git from the command line and also from 3rd-party software”. This is the recommended option.

Choosing HTTPS transport backend: Leave the default: Use the OpenSSL library

Configuring line ending conversions: Select “Checkout Windows-style, commit Unix-style line endings” — this prevents issues when collaborating with Mac/Linux users.

Configuring the terminal emulator: Select “Use MinTTY (the default terminal of MSYS2)” for the best Git Bash experience.

Configuring extra options: Leave the defaults and click Install.

Step 3: Verify the Installation

After installation, search for “Git Bash” in the Start Menu and open it. Type:

git --version

You should see the installed version number.

What is Git Bash? Git Bash is a terminal emulator for Windows that gives you a Unix-style command line experience. It comes bundled with Git for Windows and is the recommended way to run Git commands on Windows.

Common Windows Issues

Problem: *git is not recognized in Command Prompt or PowerShell* Fix: You may have skipped the PATH configuration step. Uninstall Git and reinstall, selecting "Git from the command line and also from 3rd-party software" on the PATH screen.

Problem: Line ending warnings when cloning repositories Fix: This is expected on Windows. The warning CRLF will be replaced by LF is harmless and just means Git is normalizing line endings for cross-platform compatibility.

Problem: Git Bash opens but the font is tiny Fix: Right-click the Git Bash title bar → Properties → Font tab → increase the font size.

Part 3: Installing Git on Linux

Git was born on Linux, so installation is straightforward.

Ubuntu / Debian / Linux Mint

sudo apt update
sudo apt install git

Fedora / RHEL / CentOS

sudo dnf install git

Arch Linux / Manjaro

sudo pacman -S git

openSUSE

sudo zypper install git

Verify the Installation

git --version

Updating Git on Linux

To get the latest version of Git on Ubuntu (the default APT version can be outdated), add the official PPA:

sudo add-apt-repository ppa:git-core/ppa
sudo apt update
sudo apt install git

Common Linux Issues

Problem: Permission denied when running git commands Fix: Never use sudo git for normal operations. If you see permission errors, it usually means the repository was created by another user. Fix ownership with: sudo chown -R $USER:$USER .

Problem: Old Git version despite updating Fix: Use the git-core PPA (Ubuntu) or build from source for the absolute latest version.

Part 4: Initial Git Configuration (All Platforms)

After installing Git, the very first thing you must do is tell Git who you are. This information is attached to every commit you make.

Open your terminal (Git Bash on Windows, Terminal on Mac/Linux) and run these two commands:

git config --global user.name "Your Full Name"
git config --global user.email "youremail@example.com"

Important: Use the same email address you use (or plan to use) for GitHub. This links your commits to your GitHub profile.

Set Your Default Editor

Tell Git which editor to use when it asks you to write commit messages:

# For VS Code
git config --global core.editor "code --wait"
# For Nano (beginner-friendly terminal editor)
git config --global core.editor "nano"

Set the Default Branch Name

Modern Git uses main as the default branch name (instead of the older master). Set this now to match GitHub's default:

git config --global init.defaultBranch main

View Your Configuration

To confirm everything is set correctly:

git config --list

You should see your name, email, and other settings listed.

Part 5: Core Git Concepts You Must Understand

Before jumping into commands, let’s make sure the key concepts are clear.

Repository (Repo)

A repository is a folder that Git is tracking. It contains your project files and a hidden .git folder where Git stores all the history.

There are two types:

  • Local repository — lives on your computer
  • Remote repository — lives on a server like GitHub

Commit

A commit is a saved snapshot of your project at a specific point in time. Think of it like pressing “Save” in a video game — you can always load from that point.

Every commit has:

  • A unique ID (called a hash)
  • Your name and email
  • A timestamp
  • A commit message describing what changed

Branch

A branch is an independent line of development. The default branch is called main.

Branches let you work on a new feature or bug fix without affecting the stable, working version of your project. When the work is done, you merge the branch back in.

Staging Area

The staging area (also called the index) is a middle step between editing a file and committing it. You add changes to the staging area first, then commit them. This lets you choose exactly which changes to include in each commit.

Working Directory → Staging Area → Repository

This is the three-stage flow that all Git work follows:

Working Directory  →  git add  →  Staging Area  →  git commit  →  Local Repository

Part 6: Essential Git Commands

Here are the commands you’ll use every single day as a developer.

Starting a New Repository

Initialize a new Git repository in a folder:

git init

Run this inside an existing project folder to start tracking it with Git.

Clone an existing repository from GitHub:

git clone https://github.com/username/repository-name.git

This downloads the entire repository to your local machine.

Checking Status and History

Check what’s changed in your working directory:

git status

This is one of the most-used commands. Run it constantly to see what files have been modified, what’s staged, and what’s untracked.

View the commit history:

git log

For a more compact view:

git log --oneline

See exactly what changed in a file:

git diff filename.txt

Saving Your Work (Add and Commit)

Stage a specific file:

git add filename.txt

Stage all changed files at once:

git add .

Commit your staged changes with a message:

git commit -m "Add user login feature"

Write good commit messages. A good commit message explains what changed and why. Avoid vague messages like “fix” or “update”. Use specific messages like “Fix null pointer error in user authentication” or “Add dark mode toggle to settings page”.

Stage and commit in one step (only for already-tracked files):

git commit -am "Update homepage layout"

Working with Branches

List all branches:

git branch

Create a new branch:

git branch feature/login-page

Switch to a branch:

git checkout feature/login-page

Create and switch to a new branch in one command:

git checkout -b feature/login-page

Merge a branch into main:

git checkout main
git merge feature/login-page

Delete a branch after merging:

git branch -d feature/login-page

Connecting to GitHub (Remote Repositories)

Add a remote repository:

git remote add origin https://github.com/username/repository-name.git

View your remote connections:

git remote -v

Push your local commits to GitHub:

git push origin main

Pull the latest changes from GitHub:

git pull origin main

Push a new branch to GitHub:

git push -u origin feature/login-page

Undoing Mistakes

Unstage a file (remove from staging area):

git restore --staged filename.txt

Discard changes in a file (revert to last commit):

git restore filename.txt

⚠️ Warning: This permanently discards your uncommitted changes. Use carefully.

Undo the last commit (but keep the changes in your working directory):

git reset --soft HEAD~1

View an older version of your project without changing anything:

git checkout abc1234  # Use the commit hash from git log

Go back to the latest commit:

git checkout main

Part 7: A Real-World Git Workflow

Here’s how a typical Git workflow looks when working on a project:

Scenario: Adding a New Feature

# 1. Start from the main branch
git checkout main
# 2. Pull the latest changes from GitHub
git pull origin main
# 3. Create a new branch for your feature
git checkout -b feature/contact-form
# 4. Write your code... make changes to files...
# 5. Check what's changed
git status
# 6. Stage your changes
git add .
# 7. Commit with a clear message
git commit -m "Add contact form with validation"
# 8. Push the branch to GitHub
git push -u origin feature/contact-form
# 9. Open a Pull Request on GitHub (done in the browser)
# 10. After the PR is merged, clean up locally
git checkout main
git pull origin main
git branch -d feature/contact-form

This workflow — branch, code, commit, push, pull request — is the industry standard used at companies of all sizes.

Part 8: Setting Up Git with GitHub

Step 1: Create a GitHub Account

  1. Go to **https://github.com**
  2. Click Sign Up and complete the registration
  3. Verify your email address

Step 2: Authenticate Git with GitHub

Modern GitHub no longer accepts passwords via the terminal. You’ll use one of two methods:

Option A: Personal Access Token (HTTPS — Simpler)

  1. In GitHub, click your profile photo → Settings
  2. Scroll down to Developer settingsPersonal access tokensTokens (classic)
  3. Click Generate new token
  4. Give it a name, set an expiry, and check the repo scope
  5. Click Generate token and copy the token immediately (you won’t see it again)

The next time you push to GitHub and it asks for a password, paste this token instead.

Option B: SSH Key (More Secure — Recommended)

Step 1: Generate an SSH key

ssh-keygen -t ed25519 -C "youremail@example.com"

Press Enter to accept the default file location. Optionally, add a passphrase for extra security.

Step 2: Add the key to the SSH agent

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

Step 3: Copy your public key

# Mac/Linux
cat ~/.ssh/id_ed25519.pub
# Windows (Git Bash)
clip < ~/.ssh/id_ed25519.pub

Step 4: Add the key to GitHub

  1. In GitHub, go to SettingsSSH and GPG keysNew SSH key
  2. Give it a title (e.g., “My Laptop”)
  3. Paste the public key and click Add SSH key

Step 5: Test the connection

ssh -T git@github.com

You should see: Hi username! You've successfully authenticated.

Part 9: Git in VS Code (GUI Integration)

If you’re using VS Code, you get a built-in Git GUI — no terminal required for basic operations.

The Source Control Panel

Click the branch icon in the left sidebar (or press Ctrl/Cmd + Shift + G) to open the Source Control panel.

From here you can:

  • See all changed files at a glance
  • Click the + icon next to a file to stage it
  • Type a commit message in the text box and press Ctrl/Cmd + Enter to commit
  • Use the ... menu to push, pull, and manage branches

GitLens Extension

For a supercharged Git experience in VS Code, install the GitLens extension. It adds:

  • Blame annotations — see who wrote each line of code and when
  • File history — view all past versions of a file
  • Branch comparison — see differences between branches side by side
  • Commit search — find any commit by message, author, or date

Part 10: Common Git Mistakes and How to Fix Them

“I committed to the wrong branch”

Don’t panic. Move the commit to the correct branch:

# Copy the commit hash
git log --oneline
# Switch to the correct branch
git checkout correct-branch
# Apply the commit
git cherry-pick abc1234
# Go back and remove the commit from the wrong branch
git checkout wrong-branch
git reset --hard HEAD~1

“I accidentally committed a password or secret key”

This is serious. The file is now in your Git history, even if you delete it.

  1. Immediately rotate/revoke the exposed credential (change the password, regenerate the API key)
  2. Remove the file from history using git filter-repo (the modern replacement for git filter-branch):
pip install git-filter-repo
git filter-repo --path secrets.txt --invert-paths
  1. Force-push the cleaned history and notify your team

Prevention: Always add sensitive files to .gitignore before committing. Never hardcode secrets in your code.

“I have a merge conflict”

Merge conflicts happen when two branches change the same part of the same file. Git can’t automatically decide which version to keep, so it asks you to choose.

When a conflict occurs, open the conflicting file. You’ll see something like this:

<<<<<<< HEAD
const greeting = "Hello World";
=======
const greeting = "Hi There";
>>>>>>> feature/update-greeting
  • Everything between <<<<<<< HEAD and ======= is your current branch's version
  • Everything between ======= and >>>>>>> is the incoming branch's version

Edit the file to keep whichever version you want (or combine both), delete the conflict markers, then:

git add filename.txt
git commit -m "Resolve merge conflict in greeting"

“I pushed sensitive data to a public GitHub repository”

  1. Act immediately — treat the exposed credentials as compromised and revoke them
  2. Make the repository private temporarily
  3. Clean the history with git filter-repo
  4. Force-push the cleaned repository
  5. Contact GitHub Support if needed

“git pull says ‘refusing to merge unrelated histories’”

This happens when you initialize a repository locally and also on GitHub separately. Fix it with:

git pull origin main --allow-unrelated-histories

Part 11: The .gitignore File

A .gitignore file tells Git which files and folders to ignore — meaning they'll never be committed to your repository.

Why You Need It

Some files should never be in version control:

  • Secrets.env files, API keys, passwords
  • Dependenciesnode_modules/, venv/ (these can be reinstalled from a config file)
  • Build outputdist/, build/, __pycache__/
  • OS files.DS_Store (Mac), Thumbs.db (Windows)
  • IDE files.vscode/settings.json, .idea/

Creating a .gitignore File

Create a file named .gitignore in the root of your project. Here's a practical example for a Python web project:

# Python
__pycache__/
*.pyc
*.pyo
venv/
.env
# Node.js
node_modules/
dist/
# Operating System
.DS_Store
Thumbs.db
# IDE
.vscode/
.idea/

Pro Tip: Visit **https://gitignore.io** to auto-generate a .gitignore file for your specific tech stack.

Quick Reference: The Most Important Git Commands

Command What It Does git init Initialize a new repository git clone <url> Copy a remote repository locally git status Check what's changed git add . Stage all changes git add <file> Stage a specific file git commit -m "message" Save a snapshot with a message git log --oneline View commit history (compact) git push origin main Upload commits to GitHub git pull origin main Download latest from GitHub git branch List all branches git checkout -b <name> Create and switch to a new branch git merge <branch> Merge a branch into current branch git diff See unstaged changes git restore <file> Discard changes in a file git reset --soft HEAD~1 Undo last commit, keep changes

Conclusion

Git might feel overwhelming at first — and that’s completely normal. Every developer goes through this. The commands feel strange, the terminology is unfamiliar, and merge conflicts seem terrifying.

But here’s the truth: you only need about 10 commands to handle 90% of real-world Git usage. Once those become muscle memory, everything else clicks into place.

Here’s your action plan to get started today:

  1. Install Git on your platform using the steps in this guide
  2. Configure your name and email with git config
  3. Create a free GitHub account at github.com
  4. Initialize a practice repository and make your first commit
  5. Push it to GitHub — seeing your code live on GitHub is a great motivator

The best way to learn Git is to use it on real projects, make mistakes, and figure out how to fix them. Every error is a lesson, and Git gives you the safety net to experiment freely, knowing you can always go back.

Start small. Commit often. And remember — every great developer started with git init.

Found this guide helpful? Follow me on Medium for more developer tutorials and tips. Have a Git question I didn’t cover? Drop it in the comments — I’m happy to help!

Tags: #Git #GitHub #VersionControl #Programming #Beginners #Developer #OpenSource #Coding #SoftwareDevelopment #DevTools


메타데이터
post_id
e19aa4ff6eb9
slug
git-the-complete-beginners-guide-to-version-control-e19aa4ff6eb9
url
https://medium.com/@manjunath.kvmc/git-the-complete-beginners-guide-to-version-control-e19aa4ff6eb9
canonical_url
https://medium.com/@manjunath.kvmc/git-the-complete-beginners-guide-to-version-control-e19aa4ff6eb9
author_url
https://medium.com/@manjunath.kvmc
status
ok
fetched_at
2026-06-09 15:37:30