Git Installation & Setup: Complete Beginner's Guide to Your First Repository with Real Terminal Examples

Step-by-step Git installation guide with real terminal output. Learn to install Git, configure user settings, understand repositories, the .git folder, and create your first Git repository from scratch.

17 min read

Ready to get hands-on with Git? After understanding the fundamentals of version control and the differences between VCS types, it's time to install Git and create your first repository. This tutorial follows a real terminal session, explaining every command and its output in detail.

šŸ’”

šŸŽÆ What You'll Learn: In this hands-on tutorial, you'll discover:

  • How to download and install Git on your operating system
  • Step-by-step verification that Git is properly installed
  • Essential Git configuration for collaboration
  • What a Git repository actually is and how to create one
  • Understanding the mysterious .git folder and its contents
  • The difference between working directory and repository
  • Real terminal output with detailed explanations of every message

Prerequisites: Understanding of VCS concepts from Parts 1 & 2

šŸ’¾ Installing Git: Your First Step

Download Git from Official Source

The first step is downloading Git from the official website. This ensures you get the latest, secure version directly from the Git developers.

Download Location: Visit git-scm.com

Why use the official site?

  • āœ… Latest Version: Always get the most recent stable release
  • āœ… Security: Official builds are properly signed and verified
  • āœ… OS Detection: Website automatically detects your operating system
  • āœ… Documentation: Access to complete installation guides

Operating System Specific Installation

Operating SystemInstallation MethodNotes
WindowsDownload .exe installer from git-scm.comIncludes Git Bash terminal
macOSDownload .dmg installer or use HomebrewMay come pre-installed with Xcode
Linux (Ubuntu/Debian)sudo apt update && sudo apt install gitAvailable in package managers
Linux (CentOS/RHEL)sudo yum install git or sudo dnf install gitUse dnf for newer versions

āœ… Verifying Git Installation

After installation, the first thing to do is verify that Git is properly installed and accessible from your terminal.

Testing Git Installation with Command

Let's run the basic git command to see if Git is installed:

[centos9@vbox random 16:22:25]$ git

Command Explanation:

  • git - The base Git command without any parameters
  • Purpose: Shows the main Git help screen and available commands
  • When to use: To verify Git is installed and see basic command overview

Understanding Git's Help Output

When you run git without any parameters, Git displays its usage information:

usage: git [-v | --version] [-h | --help] [-C <path>] [-c <name>=<value>]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p | --paginate | -P | --no-pager] [--no-replace-objects] [--no-lazy-fetch]
           [--no-optional-locks] [--no-advice] [--bare] [--git-dir=<path>]
           [--work-tree=<path>] [--namespace=<name>] [--config-env=<name>=<envvar>]
           <command> [<args>]

What This Output Means:

  • usage: Shows the basic syntax for Git commands
  • Options in brackets: Optional parameters you can use with Git
  • <command> [<args>]: Indicates Git expects a subcommand and optional arguments

Git Commands by Category

The help output organizes Git commands into logical categories:

CategoryKey CommandsPurpose
Start a working areaclone, initCreate or copy repositories
Work on current changeadd, mv, restore, rmStage and manage files
Examine history and statebisect, diff, log, show, statusView changes and history
Grow, mark and tweakbranch, commit, merge, rebase, tagRecord and organize changes
Collaboratefetch, pull, pushSync with remote repositories

Checking Git Version

Let's verify the specific version of Git installed:

[centos9@vbox random 16:22:26]$ git -v
git version 2.47.3

Command Explanation:

  • git -v or git --version - Shows the installed Git version
  • Purpose: Verify you have a recent version and for troubleshooting
  • Output: git version 2.47.3 indicates Git version 2.47.3 is installed
āœ…

āœ… Version Check Passed: Version 2.47.3 is a recent release with all modern features. Any version 2.20+ is recommended for beginners.

āš™ļø Essential Git Configuration

Before creating your first repository, you need to configure Git with your identity. This information will be associated with every commit you make.

Why Git Configuration Matters

Why set user.name and user.email?

In collaborative environments, Git needs to track who made each change. Every commit in Git includes:

  • Author information: Who wrote the code
  • Timestamp: When the change was made
  • Commit message: What the change does

Without proper configuration, your commits might be attributed to "unknown" or show confusing author information.

Setting Up Your Git Identity

Here are the essential configuration commands (shown as comments in our session since they were already set):

# Set your name (replace with your actual name)
git config --global user.name "Your Name"

# Set your email (replace with your actual email)
git config --global user.email "your.email@example.com"

Command Breakdown:

  • git config - The Git configuration management command
  • --global - Apply this setting to all repositories on your system
  • user.name - The configuration key for your name
  • user.email - The configuration key for your email address

Checking Current Configuration

Let's see what configuration is currently set:

[centos9@vbox random 16:25:00]$ git config --global user.name
Owais Abbasi

[centos9@vbox random 16:25:12]$ git config --global user.email
owais.abbasi9@gmail.com

Command Explanation:

  • git config --global user.name - Shows the currently configured name
  • git config --global user.email - Shows the currently configured email
  • Output: Returns the values that are currently set

Changing Git Configuration

If you need to change your configuration later:

# These commands were shown in comments in our session
git config --global user.name="Abc"
git config --global user.email="abc@gmail.com"

When to change configuration:

  • New job: Different work email and potentially different name format
  • Personal vs Work: Switch between personal and work identities
  • Correction: Fix typos in your name or email

šŸ“ Understanding Git Repositories

What is a Repository?

A repository (often called "repo") is a directory that contains your project files plus Git's tracking information. Think of it as a folder that has been "supercharged" with version control capabilities.

Repository Components:

  • Working Directory: Your actual project files that you edit
  • Git Database: Hidden .git folder containing all version history
  • Staging Area: Temporary space for changes before committing

Analogy: Think of a repository like a photo album with a time machine:

  • Working Directory = Current photos you're organizing
  • Staging Area = Photos selected for the next album page
  • Git Database = Complete album with every page (snapshot) ever created

Creating Your Project Structure

Let's follow the exact steps from our terminal session to create a project:

[centos9@vbox random 16:43:52]$ ls -al
total 0
drwxr-xr-x. 2 centos9 centos9  6 Sep 22 14:50 .
drwxr-xr-x. 5 centos9 centos9 88 Sep  2 23:06 ..

[centos9@vbox random 16:43:58]$ mkdir Repo
[centos9@vbox random 16:44:07]$ cd Repo/
[centos9@vbox Repo 16:44:19]$ mkdir myproject
[centos9@vbox Repo 16:44:28]$ cd myproject/

Command Breakdown:

  • ls -al - List all files and directories with detailed information
  • mkdir Repo - Create a directory named "Repo"
  • cd Repo/ - Change into the Repo directory
  • mkdir myproject - Create a subdirectory for our project
  • cd myproject/ - Change into the project directory

Understanding Directory Structure

[centos9@vbox myproject 16:44:33]$ ls -al
total 0
drwxr-xr-x. 2 centos9 centos9  6 Sep 22 16:44 .
drwxr-xr-x. 3 centos9 centos9 23 Sep 22 16:44 ..

Output Explanation:

  • total 0 - No files in the directory (0 blocks used)
  • drwxr-xr-x. - Directory permissions and attributes
  • . - Current directory (myproject)
  • .. - Parent directory (Repo)
  • Notice: No .git folder yet - this is just a regular directory

šŸš€ Creating Your First Git Repository

Initializing a Git Repository

Now comes the magic moment - transforming a regular directory into a Git repository:

[centos9@vbox myproject 16:44:50]$ git init
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: 	git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: 	git branch -m <name>
Initialized empty Git repository in /home/centos9/Razzaq-Labs-II/random/Repo/myproject/.git/

Command Explanation:

  • git init - Initialize a new Git repository in the current directory
  • Purpose: Transform a regular folder into a Git repository
  • What happens: Creates the .git folder with all necessary Git infrastructure

Understanding Git's Output Messages

Let's break down each part of Git's response:

Message PartExplanationAction Needed
Branch Name HintGit is using 'master' as default branch nameOptional: Can change to 'main' for modern conventions
Alternative NamesSuggests modern branch names (main, trunk, development)None - this is just informational
Success Message"Initialized empty Git repository"None - repository is ready to use
Repository PathShows exact location of .git folderRemember this path for troubleshooting

Verifying Repository Creation

Let's check what changed after running git init:

[centos9@vbox myproject 16:45:01]$ ls -l
total 0

[centos9@vbox myproject 16:45:19]$ ls -al
total 0
drwxr-xr-x. 3 centos9 centos9  18 Sep 22 16:45 .
drwxr-xr-x. 3 centos9 centos9  23 Sep 22 16:44 ..
drwxr-xr-x. 7 centos9 centos9 119 Sep 22 16:45 .git

Key Differences:

  • ls -l - Shows no visible files (same as before)
  • ls -al - Now shows the .git directory!
  • Important: The .git folder is hidden (starts with .)
  • Size change: Directory now contains 119 bytes of Git infrastructure
šŸ’”

šŸ’” Hidden Files: The .git folder is hidden by default. Use ls -al (not just ls) to see hidden files and directories that start with a dot.

šŸ” Exploring the .git Folder

What's Inside the .git Directory?

The .git folder contains all of Git's magic. Let's explore its contents:

[centos9@vbox myproject 16:45:22]$ cd .git/
[centos9@vbox .git 16:45:27]$ ls
branches  config  description  HEAD  hooks  info  objects  refs

[centos9@vbox .git 16:45:29]$ ls -al
total 16
drwxr-xr-x. 7 centos9 centos9  119 Sep 22 16:45 .
drwxr-xr-x. 3 centos9 centos9   18 Sep 22 16:45 ..
drwxr-xr-x. 2 centos9 centos9    6 Sep 22 16:45 branches
-rw-r--r--. 1 centos9 centos9   92 Sep 22 16:45 config
-rw-r--r--. 1 centos9 centos9   73 Sep 22 16:45 description
-rw-r--r--. 1 centos9 centos9   23 Sep 22 16:45 HEAD
drwxr-xr-x. 2 centos9 centos9 4096 Sep 22 16:45 hooks
drwxr-xr-x. 2 centos9 centos9   21 Sep 22 16:45 info
drwxr-xr-x. 4 centos9 centos9   30 Sep 22 16:45 objects
drwxr-xr-x. 4 centos9 centos9   31 Sep 22 16:45 refs

Understanding Each .git Component

ComponentTypePurpose
branchesDirectoryLegacy branch storage (rarely used in modern Git)
configFile (92 bytes)Repository-specific configuration settings
descriptionFile (73 bytes)Repository description for web interfaces
HEADFile (23 bytes)Points to current branch/commit
hooksDirectory (4096 bytes)Scripts that run at specific Git events
infoDirectoryAdditional repository information and global excludes
objectsDirectoryThe heart of Git: All commits, files, and trees stored here
refsDirectoryReferences to commits (branches, tags)
āš ļø

āš ļø Important: Never manually modify files in the .git directory unless you're an advanced user. Git manages this folder automatically, and manual changes can corrupt your repository.

Working Directory vs Repository

Let's return to our working directory to understand the relationship:

[centos9@vbox .git 16:45:32]$ cd ..
[centos9@vbox myproject 16:45:38]$

Directory Structure Now:

myproject/              <- Working Directory (where you edit files)
ā”œā”€ā”€ .git/              <- Git Repository (where Git stores history)
│   ā”œā”€ā”€ branches/
│   ā”œā”€ā”€ config
│   ā”œā”€ā”€ description
│   ā”œā”€ā”€ HEAD
│   ā”œā”€ā”€ hooks/
│   ā”œā”€ā”€ info/
│   ā”œā”€ā”€ objects/       <- Your commits and file history live here
│   └── refs/
└── (your project files will go here)

šŸ“Š Understanding Repository Status

Checking Repository Status

Now let's check the status of our new repository:

[centos9@vbox myproject 16:45:38]$ git status
On branch master

No commits yet

nothing to commit (create/copy files and use "git add" to track)

Breaking Down Git Status Output

Status LineMeaningWhat It Tells You
"On branch master"Currently on the master branchWhich timeline/branch you're working on
"No commits yet"Repository has no snapshotsThis is a brand new, empty repository
"nothing to commit"No changes ready to saveWorking directory is clean
"create/copy files"Suggestion for next stepAdd some files to start tracking changes

šŸŽÆ Key Concepts Summary

Working Directory Explained

Working Directory: The folder where you create and edit your project files. This is the "normal" part of your project that you interact with daily.

Key Points:

  • Contains your actual project files (code, documents, images, etc.)
  • This is where you make changes to your project
  • Git watches this directory for changes
  • Files here can be in different states: untracked, modified, staged, etc.

Repository vs Working Directory

AspectWorking DirectoryGit Repository (.git folder)
PurposeWhere you work on filesWhere Git stores history
VisibilityVisible files you editHidden, managed by Git
ContentCurrent version of your filesAll versions of your files
InteractionDirect editing with any toolManaged through Git commands

šŸŽÆ Key Takeaways

āœ… Essential Concepts Mastered

  1. Git Installation: Downloaded from git-scm.com and verified with git --version

  2. Configuration Setup: Set user.name and user.email for commit attribution

  3. Repository Creation: Used git init to transform a directory into a Git repository

  4. Hidden .git Folder: Contains all Git's tracking data and history

  5. Working Directory: The visible folder where you edit your project files

  6. Git Status: Shows current state of repository and suggestions for next steps

  7. Branch Concept: Started on 'master' branch (modern projects often use 'main')

āœ…

šŸŽ‰ Congratulations! You have successfully:

  • āœ… Installed Git and verified it works
  • āœ… Configured Git with your identity
  • āœ… Created your first Git repository
  • āœ… Understood the structure of a Git repository
  • āœ… Learned the difference between working directory and Git database

You're now ready to start tracking files and making commits! The next tutorial will show you how to add files, understand file status, and create your first snapshots.

šŸ’¬ Discussion

How did your Git installation and setup go?

  • Did you encounter any issues during installation on your operating system?
  • Which part of the .git folder structure was most surprising to you?
  • Do you understand the relationship between working directory and repository?
  • What questions do you have about Git configuration or repository setup?
Owais

Written by Owais

I'm an AIOps Engineer with a passion for AI, Operating Systems, Cloud, and Security—sharing insights that matter in today's tech world.

I completed the UK's Eduqual Level 6 Diploma in AIOps from Al Nafi International College, a globally recognized program that's changing careers worldwide. This diploma is:

  • āœ… Available online in 17+ languages
  • āœ… Includes free student visa guidance for Master's programs in Computer Science fields across the UK, USA, Canada, and more
  • āœ… Comes with job placement support and a 90-day success plan once you land a role
  • āœ… Offers a 1-year internship experience letter while you study—all with no hidden costs

It's not just a diploma—it's a career accelerator.

šŸ‘‰ Start your journey today with a 7-day free trial

Related Articles

Continue exploring with these handpicked articles that complement what you just read

More Reading

One more article you might find interesting