Creating a local Git server

Creating a local Git server

March 16, 2024

Hello everyone!

Today I’d like to share a quick and useful tip: how to create a local Git server. Imagine this situation: you and your colleague are working on an important feature in the office and you need to deliver it in just a few days. Suddenly, the internet goes down — and your mobile data isn’t working either. You urgently need to send the part you just developed to your colleague. Feeling that cold panic already?

Did you know that it’s possible to have a local Git server where you can clone and push without needing the internet, just using the internal network? That’s exactly what I’d like to show today. Let’s go!

Creating a bare repository

First, we need to define a repository as “bare”. This means it will only contain the Git metadata needed to manage the project’s versions. It’s like having a central hub to share between several developers.

To do that, run the following command:

git clone --bare /project-path /project-path-goo/project.git

Now that the bare repository has been created, let’s update the server information so that we can clone and push from our local server. Use the following command:

Now, with the bare repository created, let’s update the server information so that we can run git clone or git push from our local server with this command:

git --bare update-server-info && mv hooks/post-update.sample hooks/post-update

Explaining the commands:

  • git --bare update-server-info: Updates the server information in a bare repository. This ensures we’re working with a bare repository.
  • mv hooks/post-update.sample hooks/post-update: Moves the post-update hook sample file to the actual hook location.

Now, to verify that it actually works, just run git clone:

git clone /project-path-goo/project.git

And that’s it! Now you have a local Git server ready to use, even without an internet connection.

💬 Comentários