In this project, I set up my own Git server on an AWS EC2 instance, configured SSH keys, and learned how to create and manage repositories using the Git command line. I explored Git's internal workings, including objects and commit history, and also set up a web based Git UI for easier repository management. This hands on experience deepened my understanding of how Git functions and how to manage a custom Git server.
-
Setup Git Server on AWS EC2:
- Created an EC2 instance on AWS and downloaded the PEM file for SSH access.
- Installed Git on the EC2 instance using
sudo apt install git
. - Created a user (
git
) on the server for managing repositories.
-
Created and Configured Git Repositories:
- Initialized a bare repository (
git init --bare
) in the/var/lib/git/
directory. - Set up proper permissions and ownership for the Git repository folder.
- Explored the internal structure of a Git repository, including how commits and changes are tracked.
- Initialized a bare repository (
-
SSH Key Configuration:
- Generated an SSH key on the local machine using
ssh-keygen -t ed25519
. - Added the generated SSH public key to the
authorized_keys
file on the server for secure communication. - Successfully cloned the repository from the server to the local machine and made changes to test the setup.
- Generated an SSH key on the local machine using
-
Commit Changes and Push to Server:
- Created an
index.html
file, committed changes, and pushed them to the Git server. - Observed the creation of objects in the Git repository, including commit IDs and corresponding object files.
- Created an
-
Explored Git Internals:
- Navigated through the Git objects directory (
/var/lib/git/my-review-app.git/objects
) to see how Git stores commit data (commit hashes, file changes). - Used the
git diff
command to compare two commit versions and track file changes over time.
- Navigated through the Git objects directory (
-
Used Git UI Tools:
- Installed and explored
git-web
for a simple web interface to interact with Git repositories. - Configured the server's security group to allow inbound traffic on port
1234
for web access.
- Installed and explored
-
Worked with Multiple Projects:
- Created a second project repository on the server and repeated the process of cloning, committing, and pushing code.
- Explored how multiple repositories can be managed on the same server.
-
Git Collaboration Setup:
- Experimented with pushing and pulling code between the local machine and the server to simulate collaboration.
- Added additional commits and tracked changes using
git log
andgit diff
.
-
Create an AWS EC2 instance and download the PEM file for SSH access.
-
SSH into the machine:
ssh -i "git.pem" ubuntu@<your-ec2-ip-address>
-
Install Git:
sudo apt install git
-
Create a new user for Git:
sudo adduser git
-
Set up the repository directory:
sudo chown -R git /var/lib/git sudo su git cd /var/lib/git mkdir my-review-app.git
-
Initialize the repository:
git init --bare
-
Generate SSH key on your local machine:
ssh-keygen -t ed25519 -C "git-user" cat ~/.ssh/id_ed25519.pub
-
Copy the SSH key to the server:
ssh git@<your-ec2-ip-address> cd ~/.ssh/ vim authorized_keys
Paste the SSH key into the file.
-
Clone the repository locally:
git clone git@<your-ec2-ip-address>:/var/lib/git/my-review-app.git
-
Create a simple HTML file (
index.html
) and add it to the repository. -
Commit and push the changes:
git add . git commit -m "first commit" git push
-
Check the commit on the server: Navigate to the objects directory to see the commit:
cd /var/lib/git/my-review-app.git/objects
-
After pushing the first commit, you can check the commit ID in the
objects
folder on the server. -
Similarly, for subsequent commits, Git stores data in objects. You can use the
git diff
command to see changes between commits:git diff <commit-id-1> <commit-id-2>
-
Install Ruby and GitWeb:
sudo apt install ruby sudo apt install gitweb
-
Start GitWeb:
cd /var/lib/git/my-review-app.git git instaweb --httpd=webrick
-
Access the GitWeb UI via the browser at:
http://<your-ec2-ip-address>:1234
You can edit the project description by modifying the description
file in the repository:
vim description
To create the 3rd commit, follow these commands:
# Add changes or create new files
$ git add .
# Commit the changes with a message
$ git commit -m "third commit"
# Push the changes to the remote repository
$ git push
To create a second project, follow these steps:
- Initialize a Bare Git Repository:
Navigate to the directory where you want to create the new project, and initialize a bare Git repository:
$ cd /path/to/your/git/folder
$ git init --bare project-2.git
Initialized empty Git repository in /path/to/your/git/folder/project-2.git/
- Clone the New Repository Locally:
Clone the newly created bare repository to your local machine to start working on it:
$ git clone git@<your-ec2-ip>:<path-to-repo>/project-2.git
Cloning into 'project-2'...
warning: You appear to have cloned an empty repository.
done.
- Create Your Files and Commit Changes:
Navigate to the cloned repository directory, create the necessary files, and then add, commit, and push your changes.
$ cd project-2
$ touch index.js # Create a new JavaScript file
$ git add . # Add the files to the staging area
$ git commit -m "Initial commit for project-2" # Commit the changes
[master 123abc] Initial commit for project-2
1 file changed, 1 insertion(+)
$ git push # Push the changes to the remote repository
To git@<your-ec2-ip>:<path-to-repo>/project-2.git
7770d0e..123abc master -> master
- Verify the Changes :
You can now verify that the files have been successfully committed and pushed to your new project repository.
$ git log
commit 123abc (HEAD -> master)
Author: Your Name <[email protected]>
Date: Date
Initial commit for project-2
-
Understanding Git Internals:
- Git stores each commit as an object in its internal storage, which is organized by commit hash.
- The structure of a Git repository includes various directories and files like
objects
,refs
, andconfig
that store data about commits, branches, and configurations.
-
SSH Key Integration:
- SSH keys are essential for secure communication between the client and the server, eliminating the need for passwords.
- Learned how to generate and add SSH keys to the server for authentication.
-
Git and Collaboration:
- Git is a powerful tool for version control, and setting up a custom server helped understand the underlying process of committing changes and managing repositories.
-
Git Web Interface:
- Installing tools like
gitweb
can provide a simple web interface to manage Git repositories, enhancing collaboration and ease of use.
- Installing tools like
This project provided me with hands-on experience in Git's internal mechanics, server configuration, SSH key setup, and collaboration with a custom Git server. It enhanced my understanding of version control systems, both from a user and administrative perspective, giving me a deeper insight into how they function and are managed.