Self hosting a git repository at a tilde space

mydeardiary

2024-02-05T09:59:03.086794419+00:00

Self Hosting a Git Repository at a Tilde Space

A brief explanation about git

git is a source control system. By using git or other source control software, one will be able to have a history of what the working directory, i.e. a series of changes made to specific directory. The source control system is commonly used with computer users to track software source code or even a web developer to keep record on website changes.

Git hosting

With the popularity of git repositories, many options to host a git repo has been emerged. The first of them is Sourceforge, which old projects such as the popular 7zip archiver is hosted there. The popular GitHub make it easy to host a git repository with very user friendly web interface to browse the files inside the repository.

Git repository

git is a decentralized version control system. So a git repository is just a copy of git data.

The .git directory inside a working directory is the local git repository. This local repository will be synchronized with remote repository. In fact, a remote repository can be anything: from folder on the same disk partition, to another computer served via http or git protocol or even mounted network share folder.

If you have another computer out there and it is accessible via ssh, then you can get your own git remote repository set up. The remote repository can then be accessed via http for fetching and ssh for pushing.

Setting up a remote repository

Log into your remote computer via ssh. Create a directory, for example projects/example-project.git

mkdir -p $HOME/public_html/projects/example-project.git

Change directory to the newly created directory.

cd $HOME/public_html/projects/example-project.git

Start an empty bare git repository

git init --bare

Done. Your remote repository has been set up.

Pushing and fetching from remote repository

With the remote repository set up, one can initialize a git repository on a directory and set the directory containing bare repository as remote. This scenario can be viewed as remote repository on another directory.

mkdir -p $HOME/my_wonderful_projects/example-project
cd $HOME/my_wonderful_projects/example-project
git init
git config --local user.name "mydeardiary"
git config --local user.email "mydeardiary@tilde.club"
cat <<EOL > README.md
# Welcome to my project

This is just a sample git repository.
It is demonstrated to give a brief explanation on using git.
EOL
git add README.md
git commit

Ok, now we have a directory containing git repository with a single commit.

Now let’s set up a remote repository with the newly created bare git repository.

git remote add "my_local_remote" $HOME/public_html/projects/example-project.git

With a remote repository configured, let’s push the first commit on default git branch (master) to the remote repository.

git push "my_local_remote" master

Done. The remote bare repository has been updated with our first commit.

Sharing the git repository with the world

Since the remote repository is in public_html directory, the directory can be served as public git repository via http(s) protocol.

cd $HOME/public_html/projects/example-project.git
git update-server-info

After updating server information, the remote can be shared to the world. In case of this tilde.club webspace, the world-accessible remote repository will be placed on https://tilde.club/~"$LOGNAME"/projects/example-project.git/. (Don’t omit the trailing slash at the end, since this url is a directory).

Of course, replace "$LOGNAME" with your tilde.club user name.

Adding index.html to the remote repository

To make it easy for others to access the remote repository, create an index.html file inside the public git directory.

<!DOCTYPE html>
<html lang=en>
<head>
<title>A simple git repository example</title>
</head>
<body>
<p>This directory contains a simple git repository.</p>
<p>To clone this repository, you need git installed.</p>
<p>
<pre><code>git clone https://tilde.club/~"$LOGNAME"/projects/example-project.git</pre></code>
</p>
</body>

With this set up, you can share the link of the public git repository to the world.

So that is how simple a git repository can be.

Real world example of this setup

Well, if you are curious to find the real world example of this simple git repository set up, you may visit my simple python based markdown to html converter.

Update: local mirror of python webspace is available.

Thanks for visiting my tilde space.


Donate to the author

Back to main page