Home-Software Development-Guide to Setting Up a Git Repository on LAN
Git repository

Guide to Setting Up a Git Repository on LAN

This guide outlines how to quickly and securely set up a Git repository on your Local Area Network (LAN) for internal team collaboration. Here’s a step-by-step breakdown to help you work efficiently:

1. Prerequisites

Before you begin, ensure you have:

  • A Linux machine with Git installed.
  • An SSH key pair for secure authentication.
  • A user with sudo privileges (if you need to install required tools).

Install Git: Use the following commands for different Linux distributions:

  • Ubuntu: sudo apt-get install git -y
  • Fedora: sudo dnf install git -y
  • Arch: sudo pacman -S git

2. Set Up the Git User and SSH Authentication

To set up a repository, it’s recommended to create a dedicated Git user for better control over authentication.

Create Git User:

  1. On the remote machine, create a Git user:

        sudo adduser git  

Set a strong password and answer the prompts.

2. Switch to the Git user:

        su git  

Navigate to the Git user’s home directory:

        cd  

Set Up SSH Directory:

  1. Create the .ssh directory:

        mkdir .ssh
chmod 700 .ssh  

2. Create the authorized_keys file:

        touch .ssh/authorized_keys
chmod 600 .ssh/authorized_keys  

Add SSH Keys:

  1. From the local machine, view the public key:

        cat /home/USER/.ssh/id_rsa.pub  

If you don’t have SSH keys, generate them with:

        ssh-keygen  

2. Copy the public key and add it to the remote machine:

        nano /home/git/.ssh/authorized_keys  

Paste the copied content into the file and save.

3. Create the Repository

Create and Initialize Repository:

  1. On the remote machine, create a directory for your repository:
        mkdir /home/git/repository
cd /home/git/repository
mkdir my_project
cd my_project  

Initialize a bare repository to allow collaboration:

        git init --bare --shared  

4. Clone the Repository Locally

On your local machine, clone the new repository using:

        git clone git@SERVER:/home/git/repository/my_project  

Where SERVER is the IP address or hostname of the remote machine.

Verify the remote repository:

        git remote -v  

5. Work with the Repository

Add and Push Changes:

  1. Create a README file in the local clone:
        nano README  

Add any desired content, then stage and commit the changes:

        git add --all
git commit -m "Added README file"
git push origin master  

2. Verify changes on the remote machine:

        nano /home/git/repository/my_project/README  

Pull Changes: From the local machine, pull the changes to update:

        git pull  

6. Grant Access to Other Team Members

To allow other team members access, add their public SSH keys to the authorized_keys file of the Git user.

Conclusion

Setting up a Git repository on a LAN provides a quick, secure, and cost-effective way for your team to collaborate on a project. By following the steps outlined above, you can establish a fully functioning Git environment without relying on external hosting services like GitHub, making it ideal for internal, temporary, or isolated projects.

logo softsculptor bw

Experts in development, customization, release and production support of mobile and desktop applications and games. Offering a well-balanced blend of technology skills, domain knowledge, hands-on experience, effective methodology, and passion for IT.

Search

© All rights reserved 2012-2024.