What is a Bare Repository?

 

🖥️ What is a Bare Repository?

A bare Git repository is a special type of repository that contains only the Git version history and metadata, without a local copy of the actual project files.

FeatureNormal (Non-Bare) RepositoryBare Repository
ContentsThe project's working files (the code you edit) PLUS a hidden .git folder with the history.ONLY the contents of the .git folder (the history).
Working DirectoryYes (You can edit files here).No (You cannot edit files or run the code directly).
PurposeLocal development (cloned by a developer to work on the code).Central coordination (used on a server like GitHub or GitLab to share and synchronize changes among multiple developers).
ConventionThe directory name is the project name (e.g., my-project).The directory name usually ends with .git (e.g., my-project.git).

Analogy: A bare repo is like the main server drive in a library—it holds the master record of all books and revisions, but you don't read or write in that drive. A normal repo is like the local copy you check out to read and make notes in.


🚀 How to Work in Git (The Basic Workflow)

Working in Git involves a three-stage process: your local environment, the staging area, and the repository history.

1. Initialization and Cloning

GoalCommandDescription
Start a NEW projectgit initInitializes a normal repository in the current directory.

Start from a REMOTEgit clone <URL>Downloads an existing (usually bare) repository from a remote server (like GitHub) and creates a normal local repository for you to work in.

2. The Cycle of Saving Changes (Local Work)

This is the core of your day-to-day work in Git.

StageCommandPurpose
WorkEdit files in your project directory.Your files are in the Working Directory. Git knows they're modified.
Checkgit statusShows which files are modified and which are staged for the next commit.
Stagegit add <file> or git add .Moves modified files from the Working Directory to the Staging Area. This marks them for inclusion in the next commit.
Commitgit commit -m "Your descriptive message"Takes a snapshot of everything in the Staging Area and permanently saves it into your local Git Repository History.

3. Sharing Your Changes (Remote Work)

Once you have committed changes locally, you share them with the bare remote repository.

CommandPurpose
git pullFetch changes from the remote repository and automatically Merge them into your current local branch. (Do this before you start new work to ensure you're up-to-date).

git pushUploads your local commits to the remote (bare) repository so your teammates can see them.

No comments:

Post a Comment