GIT REPOSITORY SETUP SUMMARY =========================== OVERVIEW -------- You have a local bare repository (demo.git) as the source of truth, mirrored on a VPS. Users can clone from the VPS and push/pull changes to stay synchronized. Branch: main (not master) INITIAL VPS SETUP (done once) ----------------------------- SSH into VPS as ubuntu user: ssh ubuntu@your_vps_ip Create bare repository as git user: sudo su - git mkdir -p /home/git cd /home/git git init --bare demo.git The bare repository is ready to receive pushes. YOUR LAPTOP CONFIGURATION ------------------------- Working directory: /home/me/demo Bare repository: /home/me/demo.git Set up dual remotes to push to both local and VPS: cd /home/me/demo git remote set-url origin /home/me/demo.git git remote add vps ssh://git@your_vps_ip/~/demo.git git remote set-url --add --push origin /home/me/demo.git git remote set-url --add --push origin ssh://git@your_vps_ip/~/demo.git First sync (push all branches and tags): git push -u origin --all git push -u origin --tags Verify configuration: git remote -v When you push, both repositories are updated: git push origin main USER ACCESS SETUP (per user) ---------------------------- One-time setup for each user: 1. User generates SSH key (if they don't have one): ssh-keygen -t ed25519 -C "their_email@example.com" (accept defaults) 2. User sends you their public key (~/.ssh/id_ed25519.pub) 3. You add their key to the git user on VPS: ssh ubuntu@your_vps_ip sudo su - git cat >> ~/.ssh/authorized_keys (paste their public key, then Ctrl+D) CLONING FROM VPS ---------------- Users clone with: git clone ssh://git@your_vps_ip/~/demo.git This automatically sets up 'origin' remote pointing to the VPS repository. Verify: git remote -v PUSHING CHANGES --------------- Users push to VPS with: git push origin main This updates the VPS repository, which you can then pull from your laptop. PULLING CHANGES --------------- If user1 pushed to VPS and user2 wants to get their changes: User2 pulls from VPS: git pull vps main If user2 also has a local bare repo, they can then sync it: git push origin main YOUR LAPTOP - PULLING USER CHANGES ---------------------------------- When users push to the VPS, pull those changes to your laptop: git pull vps main Then push to your local bare repo: git push origin main PATHS EXPLAINED --------------- /home/me/demo.git - Your local bare repository (source of truth) /home/me/demo - Your local working directory ssh://git@your_vps_ip/~/demo.git - Remote VPS repository The ~/demo.git path expands to /home/git/demo.git but hides the full path. SUMMARY OF WORKFLOWS -------------------- YOUR LAPTOP: git push origin main (pushes to both local demo.git and VPS) git pull vps main (pulls changes pushed by other users to VPS) USER CLONING: git clone ssh://git@your_vps_ip/~/demo.git USER PUSHING: git push origin main (pushes to VPS) USER PULLING: git pull origin main (pulls from VPS) OR git pull vps main (if they have dual origins like you do) KEY POINTS ---------- - Main branch is 'main' (default since Git 2.28) - SSH key authentication: secure and requires minimal setup - VPS path is hidden using ~/ syntax - Users need SSH keys added to ~/.ssh/authorized_keys on VPS - All pushes and pulls use SSH (ssh://git@your_vps_ip/~/demo.git)