Git is an open source version control system used by thousands of developers around the world to track your software changes at the source code level. It allows you to track changes, revert them to a previous stage and create alternate versions of files and directories.
HTTP Git Server is an open source project that uses an Nginx web server to serve Git repositories over a local area network (LAN). It’s simple and easy to set up, and anyone can manage it from a command-line interface.
In this tutorial, I’ll explain how to set up an HTTP Git repository server on Debian 11 using Nginx.
Prerequisites
- A server running Debian 11.
- A valid domain name pointing to your server’s IP.
- The root password configured on your server.
Installing Nginx and Other Dependencies
First, you need to install the Nginx web server and other required packages to set up your HTTP Git server. You can install all of these using the following command.
|
|
After installing all the packages, you can continue to the next step.
Creating a Git Repository
Next, you need to create a directory to store your Git repository. Let’s create a directory called myrepo in the Nginx web root.
|
|
Next, change the directory to myrepo and create another directory for the user.
Next, navigate to the user directory and initialize the Git repository with the following command.
You will get the following outputs.
|
|
Next, update the Git server information with the following command.
|
|
Next, change the ownership of myrepo and set the appropriate permissions using the following command.
Next, create a user named user1 and set the password.
|
|
You can set a password as follows.
You can check your password using the following command.
|
|
Example output.
|
|
Configuring Nginx to Serve a Git Repository
Next, you need to create an Nginx virtual host profile to serve the Git repository.
|
|
Add the following lines.
|
|
When you are done, save and close the file, then verify that Nginx does not have any syntax errors.
|
|
You will get the following outputs.
Finally, restart the Nginx service to apply the changes.
|
|
You can also check Nginx status using the following command.
|
|
You will get the following outputs.
|
|
Connecting to a Git Repository from a Client
This completes the Git HTTP server and Nginx build. Now, it’s time to connect to it from the client machine and test it.
First, install the Git package on the client machine using the following command.
|
|
Next, create a directory for your project using the following command.
|
|
Next, navigate to your project directory and initialize Git with the following command.
Next, configure Git with your email and user name:
Next, add your Git HTTP server using the following command.
|
|
Next, create a directory named dev01 and add a file to it.
Next, add the directories and files you created to your Git repository.
|
|
Next, commit the changes using the following command.
|
|
You will get the following outputs.
Next, upload your files and directories to the HTTP Git server using the following command.
|
|
You will be asked to provide a password to access the Git server.
|
|
After connecting, you will get the following output.
You can also download your repository directly from the Git server using the following command.
|
|
You will get the following outputs.
Conclusion
In the above guide, you learned how to set up an HTTP Git server on Debian 11 using Nginx, and you can now implement this setup in your local development environment and use the command line to manage and track your projects.