VOOZH about

URL: https://thenewstack.io/git-set-up-a-local-repository-accessible-by-lan/

⇱ Git: Set Up a Local Repository Accessible by LAN - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.

What’s next?

Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.

Follow TNS on your favorite social media networks.

Become a TNS follower on LinkedIn.

Check out the latest featured and trending stories while you wait for your first TNS newsletter.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2024-09-28 09:00:10
Git: Set Up a Local Repository Accessible by LAN
tutorial,
Networking / Software Development

Git: Set Up a Local Repository Accessible by LAN

How to quickly and securely deploy a Git repository on your Local Area Network for you and other team members to use.
Sep 28th, 2024 9:00am by Jack Wallen
👁 Featued image for: Git: Set Up a Local Repository Accessible by LAN

A Git repository simplifies the sharing of code to a team. Many teams opt to go the GitHub route but there might be an occasion when you need to spin up a quick repository that is only available to those team members working on your LAN.

When you need to deploy a Git repository on your LAN and you need to give other team members access to it, the goal is to do it quickly and securely. Thanks to git and Secure Shell (SSH), this isn’t nearly as challenging as you might think. And although this setup might not be an option for team members who work outside of your LAN, it’s great for a temporary repository offered to those within your company network.

How does it work? Let me show you.

What You’ll Need

To make this work, you’ll need the following:

  • A Linux machine with Git installed.
  • An SSH key pair.
  • A user with sudo privileges (if the minimum requirements aren’t installed).

That’s it. Let’s make some Git magic.

Installing Git

On the off-chance Git isn’t installed, here’s how you can take care of that:

  • Ubuntu-based distributions – sudo apt-get install git -y
  • Fedora-based distributions – sudo dnf install git -y
  • Arch-based distributions – sudo pacman -S git

Create a Git User and Add the Required SSH Keys

First, we’re going to be talking about a remote and local machine. The remote machine will be the machine that houses the repository and the local machine(s) will access the remote repository.

Once Git is installed, you’ll want to add a specific user for authentication (because you don’t want to give other team members your username and password) on any/all remote machines that will access the repository. To create the new user, issue the command:

sudo adduser git

Make sure to give the user a strong/unique password and answer the remaining questions.

Change to the new user with the command:

su git

You should now be in the Git user’s home directory. To make sure of that, issue the command:

cd

Create the necessary directory that will house the authorized keys with the command:

mkdir .ssh

Give that directory the necessary permissions with the following:

chmod 700 .ssh

Create the authorized_keys file with:

touch .ssh/authorized_keys

Give that file the necessary permissions with the following:

chmod 600 .ssh/authorized_keys

Next, head over to the local machine and view the contents of the id_rsa.pub file for the user who’ll be accessing the remote repository with the command:

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

Where USER is the Linux username that will be working with the git repository.

If you’ve not already created SSH keys, the command for this is:

ssh-keygen

Copy the contents of that file.

Go back to the remote machine and open the authorized_keys file with:

nano /home/git/.ssh/authorized_keys

In that file, paste the content from the id_rsa.pub file and save it.

So far so good.

Creating the Repository

It’s now time to create the actual repository. On the remote machine, issue the command:

mkdir /home/git/repository

Note: You can name the directory anything you like.

Change into that directory with the command:

cd /home/git/repository

Next, create a directory for a project with the command:

mkdir my_project

Again, you can name the project directory whatever you like.

Change into that new directory with:

cd my_project

Initialize the bare repository with the command:

git init --bare --shared

The bare option creates a repository with no content and the shared option ensures multiple people will be able to access it.

All right.

Your repository is ready to be cloned from the remote machine to the local machine.

Cloning the Repository

Go back to the local machine and clone the new repository with the command:

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

You should see the following in the output:

Cloning into ‘my_project’…
warning: You appear to have cloned an empty repository.

You can verify the remote repository with:

git remote -v

You should see something like this:

origin git@192.168.1.166:/home/git/repository/my_project (fetch)
origin git@192.168.1.166:/home/git/repository/my_project (push)

Now that we’ve verified, let’s create a README file on the local machine. From within the my_project directory, issue the command:

nano README

You can add whatever information to that file you need. Once you’ve done that, save and close the file. Next, add the file to staging with:

git add --all

You’ll then need to create your first commit with:

git commit -m "Added README file"

Finally, push the changes to the remote repository with:

git push origin master

You should see the README file in the repository on the remote machine. If not, you might have to check out the master branch (on the remote machine) with the command:

git checkout master

Let’s try one more thing.

On the remote machine, open the newly added README file with:

nano /home/git/repository/my_project/README

Change the contents of that file (you can add your name or anything you like).

Save and close the file.

Place the file into staging with the following:

git add .

Add a commit with:

git commit -m "Edited README file"

Back on the local machine issue the command:

git pull

When the pull completes, you can view the contents of the README and see that the changes are present.

And that’s all there is to creating a LAN-accessible Git repository. Make sure you add the id_rsa.pub key from any local machine to the authorized_keys file on the repository machine for those who need access and you should be good to go.

TRENDING STORIES
Jack Wallen is what happens when a Gen Xer mind-melds with present-day snark. Jack is a seeker of truth and a writer of words with a quantum mechanical pencil and a disjointed beat of sound and soul. Although he resides...
Read more from Jack Wallen
SHARE THIS STORY
TRENDING STORIES
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.