Skip to content

Instantly share code, notes, and snippets.

@jasonacox
Last active November 1, 2025 16:43
Show Gist options
  • Select an option

  • Save jasonacox/4f713c7926411da42025072c26562e1f to your computer and use it in GitHub Desktop.

Select an option

Save jasonacox/4f713c7926411da42025072c26562e1f to your computer and use it in GitHub Desktop.
Create a Git Server

Create a Simple Git Server

This gist provides the steps needed to create a simple gist server without using a centralized tool (e.g. GitHub).

Server Side

Log in to your linux server:

# SSH into your server
ssh [email protected]

Create and initialize Git:

#!/bin/bash

# Create your project directory and initialize Git
mkdir -p ~/projects/my-app
cd ~/projects/my-app
git init -b main
touch README.md
git add .
git commit -m "Initial commit"

# Key: Allow pushes to the current branch
git config receive.denyCurrentBranch updateInstead

# Option: Make the repo publically cloneable
git update-server-info
cp .git/hooks/post-update.sample .git/hooks/post-update
chmod +x .git/hooks/post-update
# Required: Webserver to serve up repo ~/projects/my-app

# Done
echo "Git server ready at ~/projects/my-app"

Client Side

# Create local git
mkdir my-app
cd my-app
git init -b main

# Add your server as a remote
git remote add production ssh://[email protected]/home/user/projects/my-app

# Pull from the server to your local
git pull production main                                                   

# TEST: Push your main branch to the server
touch FROM_CLIENT
git add .
git commit -m "From Client"
git push --set-upstream production main

# Option: Pull or clone from public endpoint
git clone https://yourserver.com/repos/my-app/.git

Automated Git Hook

You can set up a hook to do a build or other work when a push is done on the server.

# Create the script on the server
nano ~/projects/my-app/.git/hooks/post-update

# Make it executable
chmod +x .git/hooks/post-update

The post-update script woudl look something like this:

#!/bin/bash
set -euo pipefail

cd /home/username/projects/my-app

npm ci --production
npm run build
pm2 restart my-app

echo "Deploy complete: $(date)"

Credit and References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment