2.3K Views

GIT103 - Understanding Repositories

Learn how Git repositories work, the difference between local and remote repos, and how Git stores your project history internally.

Understanding how Git repositories work is essential to mastering version control.
A repository (often called a "repo") is where Git stores your project files, history, and metadata.
In this chapter, you will learn how local and remote repositories operate and how they work together in real development workflows.

What Is a Git Repository?

A Git repository is a structured storage area containing:

  • All your project files
  • The entire history of file changes
  • Commit metadata
  • Branches and tags
  • Configuration files used by Git

A repository is created when you run:

git init

This command creates a hidden directory named .git inside your project.
This folder contains the complete database of your repository.


Local Repositories

A local repository exists entirely on your computer.
It includes three main components:

  • Working Directory
  • Staging Area (Index)
  • Repository (the .git folder)

Local repositories allow you to:

  • Commit offline
  • Create new branches
  • Restore previous versions
  • Experiment without risk
  • Manage your complete history locally

No internet connection is required to use Git locally.


Remote Repositories

A remote repository is a version of your project stored on a server.
Popular hosting services include:

  • GitHub
  • GitLab
  • Bitbucket

Remote repositories enable:

  • Cloud backup of your project
  • Collaboration with teams
  • Pull Requests and code reviews
  • Issue tracking
  • Continuous Integration (CI) setups

You sync changes between your local and remote repositories using Git commands like push and pull.


Linking a Local Repository to a Remote

After creating a repository on a platform such as GitHub, you can link it to your local project:

git remote add origin https://github.com/username/myproject.git

Verify that the remote was added:

git remote -v

You will see:

origin https://github.com/username/myproject.git (fetch)
origin https://github.com/username/myproject.git (push)

Cloning an Existing Remote Repository

To download a remote repository and set it up locally:

git clone https://github.com/username/myproject.git

Cloning will automatically:

  • Create a project folder
  • Copy all project files
  • Download the entire commit history
  • Configure the remote named "origin"
  • Set the default branch

After this, you can start committing immediately.


Inspecting Repository Structure

To see which files Git is tracking:

git ls-files

To view hidden files:

ls -a

Inside the .git folder, you will find:

  • objects/ (stores commits, trees, versions)
  • refs/ (branches and tags)
  • config (repository settings)
  • HEAD (points to the current branch)

These internal files should not be edited manually.


Changing or Removing a Remote

Remove a remote:

git remote remove origin

Update a remote URL:

git remote set-url origin https://newurl.git

Summary

In this chapter, you learned:

  • What a Git repository is
  • How local and remote repositories work
  • How Git organizes and stores your project history
  • How to connect a local repo to a remote server
  • How to clone existing repositories
  • How to inspect repository structure and remotes

With this foundational knowledge, you are now ready to explore essential Git commands in the next chapter.