This gist provides the steps needed to create a simple gist server without using a centralized tool (e.g. GitHub).
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"# 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/.gitYou 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-updateThe 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)"- You Don’t Need GitHub: Your SSH Server Is Already a Git Host - The Atomic Architect - https://medium.com/@the_atomic_architect/you-dont-need-github-your-ssh-server-is-already-a-git-host-8dd9a8c1f283