Git Day 1: Creating a Central Bare Repository¶
Today, I officially started my journey with Git, the cornerstone of modern software development. My first task wasn't on my local machine, but on a server. The goal was to set up a central, shared repository that a whole development team could use to collaborate on a project.
This task taught me the critical difference between a regular "working" repository and a "bare" repository, which is essential for any multi-developer workflow.
Table of Contents¶
- The Task
- My Solution & Command Breakdown
- My Learning Journey: Failures & Solutions
- Why Did I Do This? (The "What & Why")
- Deep Dive: Bare vs. Working Repositories
- Exploring the Commands Used
The Task¶
On the designated Storage Server, I was required to:
1. Install the git software package.
2. Create a new, bare Git repository at the location /opt/cluster.git.
My Solution & Command Breakdown¶
After connecting to the server, the process involved two main commands.
1. Install Git¶
First, I had to ensure the Git software was available on the server.
sudo yum install -y git
2. Create the Bare Repository¶
This is the core of the task. The --bare flag is the key to creating a central repository.
sudo git init --bare /opt/cluster.git
3. Verify the Creation¶
To confirm it worked, I listed the contents of the new directory. A bare repository contains only the internal Git tracking files and folders, not the actual project files.
ls -l /opt/cluster.git
HEAD, config, and folders like objects and refs, confirmed my success.
My Learning Journey: Failures & Solutions¶
Before I could even run any commands, I hit a snag trying to connect to the server.
- The Failure: SSH Connection Refused.
- Symptom: When I tried to
sshinto theStorage Server, I immediately got an error message:"System is booting up. Unprivileged users are not permitted to log in yet. Please come back later." - Reasoning: This wasn't an error with my command or password. The virtual machine for the lab was still in the middle of its startup process. For security, many Linux systems are configured to refuse logins from regular users until all essential services are up and running.
- The Solution: The fix was incredibly simple: patience. I waited about 30-60 seconds and tried the exact same
sshcommand again. By then, the server had finished booting and it let me log in without any issues.
- Symptom: When I tried to
Why Did I Do This? (The "What & Why")¶
The purpose of this task is to create a central "source of truth" for a software project. In a team, every developer works on their own copy of the code on their local machine. To share their work and get updates from others, they need a central place to synchronize.
This bare repository on the server acts as that central hub. Developers will clone the repository to their machines, make changes, and then push their new commits back to this central location. This is the fundamental workflow of collaborative development with Git.
Deep Dive: Bare vs. Working Repositories¶
This was the most important concept I learned today.
-
A Working Repository (Normal): This is what you create on your own computer when you run
git initin a project folder. It contains two things:- The Working Directory: The actual project files that you can see and edit (e.g.,
index.html,app.js). - The
.gitDirectory: A hidden folder that contains all of Git's history, commits, branches, and tracking information.
- The Working Directory: The actual project files that you can see and edit (e.g.,
-
A Bare Repository (Central Hub): This is what I created on the server with
git init --bare. It contains only the contents of the.gitdirectory. It has no working directory. You cannotcdinto it and see your project files.- Why must it be bare? Its only job is to receive and send Git data (
pushesandpulls). If it had a working directory, it would be possible for someone to edit the files directly on the server, creating changes that aren't tracked by Git. This would lead to massive conflicts and chaos when developers tried to push their own work. A bare repository enforces the rule that all changes must come through a propergit push.
- Why must it be bare? Its only job is to receive and send Git data (
Exploring the Commands Used¶
- sudo yum install -y git: A standard Linux command to install software. yum is the package manager, -y automatically says "yes" to prompts, and git is the package I needed.
- sudo git init --bare /opt/cluster.git:
- git init: The command to initialize a repository.
- --bare: The critical flag that tells Git not to create a working directory, making it suitable for a central server.
- /opt/cluster.git: The location on the server's filesystem for the repository. The .git suffix is a common naming convention for bare repositories to make them easily identifiable.