Skip to content

Git Level 2, Task 1: Initializing a Non-Bare Repository

Today's task was about a fundamental Git operation: initializing a new repository. However, it came with a very specific and highly unusual requirement: to create a non-bare repository in a central server location. This was a fascinating task because it forced me to go against standard practice and truly understand the difference between a "working" repository and a "bare" one.

This document is my detailed, first-person account of that process. I'll explain the commands I used, the concepts behind them, and a deep dive into why this task was so unique.

Table of Contents


The Task

My objective was to set up a new Git repository on the Storage Server. The specific requirements were: 1. Install the git package using yum. 2. Create a new Git repository at /opt/ecommerce.git. 3. Crucially, the task specified "make sure not to create a bare repository."


My Step-by-Step Solution

The process was very straightforward, but I had to pay close attention to the "non-bare" requirement.

Step 1: Connect and Install Git

First, I needed to get onto the correct server and ensure the Git software was available. 1. I connected to the Storage Server (e.g., ssh natasha@ststor01). 2. I installed the git package using yum. I needed sudo because installing software is an administrative action.

sudo yum install -y git

Step 2: Create the Non-Bare Repository

This was the core of the task. I used the git init command without the --bare flag. 1. I ran the command to create the repository in the /opt directory. I needed sudo again because /opt is a system directory owned by root.

sudo git init /opt/ecommerce.git
The output was: Initialized empty Git repository in /opt/ecommerce.git/.git/

Step 3: Verification

The output of the init command was the first clue, but I confirmed it with ls. 1. I listed the contents of the new directory.

sudo ls -la /opt/ecommerce.git
2. The output clearly showed a hidden .git subdirectory inside /opt/ecommerce.git.
total 8
drwxr-xr-x 3 root root 4096 Oct 17 12:00 .
drwxr-xr-x 4 root root 4096 Oct 17 12:00 ..
drwxr-xr-x 7 root root 4096 Oct 17 12:00 .git
This was the definitive proof. A non-bare repository is a directory that contains a .git folder. A bare repository is the .git folder. I had successfully followed the task's unusual instruction.


Why Did I Do This? (The "What & Why")

- git: Git is a distributed version control system. It's the industry standard for tracking changes in source code during software development. - git init: This is the command that creates a new, empty Git repository. It creates the hidden .git directory that contains all the files and metadata necessary for version tracking. - Non-Bare Repository (or "Working Repository"): This is the standard repository that a developer uses on their local machine. It consists of two parts: 1. The Working Tree: The actual project files that I can see and edit. 2. The .git Directory: The hidden "brain" of the repository that stores all the commit history, branch information, and configuration. - The "Why" of this Task: The task was a test of my understanding of the git init command's options. By explicitly asking for a non-bare repository in a server path, the task was testing if I knew the difference and if I would be able to resist the muscle memory of typing git init --bare, which is the standard for server repositories.


Deep Dive: Bare vs. Non-Bare (Working) Repositories

This task was the perfect opportunity to solidify the difference between the two types of Git repositories.

[Image of a central bare Git repository with developers pushing and pulling]

Feature Non-Bare (Working) Repository Bare Repository
What I Created Yes (This task) No
Purpose A developer's local workspace for coding, adding, and committing. A central hub for sharing code. The "single source of truth."
Location Typically on a developer's laptop. On a shared server (e.g., /opt/, /git-data/).
Working Files Yes. You can see index.html, app.py, etc. None. You cannot see or edit the project files directly.
Structure A project directory with a hidden .git subdirectory inside. Looks like the contents of a .git directory (HEAD, objects, refs, etc.).
Creation Command git init or git clone git init --bare
Key Limitation You cannot push to the checked-out branch. This is the main reason it's almost never used as a central server repo. Can receive push operations from developers. This is its entire purpose.

By asking for a non-bare repository, the task had me create a "working directory" on the server. This is not a standard practice because if any developer tries to push their code to the master branch of this repository, their push will be rejected by default to prevent conflicts with the (empty) files in the server's working tree.


Common Pitfalls

- Creating a Bare Repo by Mistake: The most common mistake on this specific task would be to follow standard practice and run sudo git init --bare /opt/ecommerce.git. This would have created the wrong type of repository and failed the validation. - Permissions Issues: The /opt directory is owned by root. Forgetting to use sudo when running the git init command would have resulted in a "Permission denied" error. - Verification Confusion: Not knowing the difference in the ls -la output. Seeing a .git subdirectory was the key to proving I had created a non-bare repository. If I had created a bare repo, the ls -la /opt/ecommerce.git command would have shown files like HEAD, config, etc., directly.


Exploring the Commands I Used

- sudo yum install -y git: A standard Linux command to install software. - sudo: Executes the command with superuser (administrator) privileges. - yum: The package manager for this RHEL-based system. - -y: Automatically answers "yes" to any confirmation prompts. - sudo git init /opt/ecommerce.git: The primary command for this task. - git init: The command to initialize a new Git repository. - By omitting the --bare flag, I explicitly created a non-bare (working) repository at the specified path. - sudo ls -la /opt/ecommerce.git: My verification command. - ls: The list command. - -l: Shows the long format. - -a: Shows all files, including the hidden .git directory, which was essential for my verification.