Sometimes instead of using a public service like GitHub, you want to host your own origin server. This is handy for both backups and replication. And best of all, it’s private.
Section 1:
Connecting an Existing Git Repo to a Private Origin Server
1. ON THE ORIGIN SERVER:
Ensure git is installed and then Initialize a Bare Repository:
Bash
mkdir -p /path/to/repo.git
cd /path/to/repo.git
git init --bare
2. ON YOUR LOCAL MACHINE:
Configure your Git Username and Email (if not set):
Bash
git config --global user.name "Your Name"
git config --global user.email "youremail@example.com"
3. Add the Remote Origin to Your Local Repository:
Bash
git remote add origin ssh://username@hostname:/path/to/repo.git
4 Verify the Remote URL:
Bash
git remote -v
5. Push Your Local Repo to the Origin Server for the First Time:
Bash
git push -u origin main
6. Now you Can Perform Pushes and Pulls, and Other Operations Easily.
Bash
git push
Bash
git pull
Section 2:
Changing/Editing the Origin Server Location
Change the Remote URL:
Bash
git remote set-url origin ssh://newusername@newhost:/new/path/to/repo.git
Verify the Updated Remote URL:
Bash
git remote -v
Leave a Reply