DEV Community

Cover image for Move Your Repository to a New GitHub Repo on a VPS Hosting Site
raielly
raielly

Posted on

Move Your Repository to a New GitHub Repo on a VPS Hosting Site

⚠️ Warning: Live site may go offline temporarily. Perform during low-traffic or maintenance time.

Step 1: Prepare the New GitHub Repository

# Clone local repository
git clone **YOUR_LOCAL_REPO_PATH**
cd **YOUR_LOCAL_REPO_FOLDER**

# Remove old Git history and reinitialize
rm -rf .git
git init

# Add new repository as remote
git remote add origin git@github-company:**YOUR_ORG/YOUR_NEW_REPO.git

# Push to new repository
git add .
git commit -m "Initial commit"
git push -u origin main
Enter fullscreen mode Exit fullscreen mode

Step 2: Generate SSH Key on VPS

# Generate new SSH key
ssh-keygen -t rsa -b 4096 -C "deploy@**YOUR_COMPANY.com**"

# Save key as
# /home/**YOUR_USER**/.ssh/id_rsa_company

# Copy public key
cat ~/.ssh/id_rsa_company.pub
Enter fullscreen mode Exit fullscreen mode
  • Paste the copied key into GitHub → Settings → Deploy Keys
  • Check Allow write access

Step 3: Configure Multiple SSH Keys

nano ~/.ssh/config
Enter fullscreen mode Exit fullscreen mode

Add the following:

# Personal GitHub
Host github-personal
    HostName github.com
    User git
    IdentityFile /home/**YOUR_USER**/.ssh/id_rsa
    IdentitiesOnly yes

# Company GitHub
Host github-company
    HostName github.com
    User git
    IdentityFile /home/**YOUR_USER**/.ssh/id_rsa_company
    IdentitiesOnly yes
Enter fullscreen mode Exit fullscreen mode
  • Save and exit (CTRL + O, ENTER, CTRL + X) Test the connection:
ssh -T git@github-company
Enter fullscreen mode Exit fullscreen mode

Expected output:

Hi **YOUR_COMPANY**! You've successfully authenticated, but GitHub does not provide shell access.
Enter fullscreen mode Exit fullscreen mode

Step 4: Deploy Code on VPS

# Navigate to web root
cd /home/**YOUR_USER**/htdocs

# Backup old site
mv **YOUR_SITE_FOLDER** **YOUR_SITE_FOLDER**.bak

# Clone new repository
git clone git@github-company:**YOUR_ORG/YOUR_NEW_REPO.git **YOUR_SITE_FOLDER**

# Configure environment variables
cd **YOUR_SITE_FOLDER**
cp .env.example .env
vim .env
Enter fullscreen mode Exit fullscreen mode

Update the following placeholders in .env:

APP_NAME=**YOUR_APP_NAME**
APP_ENV=**YOUR_APP_ENV**
APP_DEBUG=true/false
APP_URL=https://**YOUR_DOMAIN.com**

DB_CONNECTION=**YOUR_DB_CONNECTION**
DB_HOST=**YOUR_DB_HOST**
DB_PORT=**YOUR_DB_PORT**
DB_DATABASE=**YOUR_DB_NAME**
DB_USERNAME=**YOUR_DB_USER**
DB_PASSWORD=**YOUR_DB_PASSWORD**
Enter fullscreen mode Exit fullscreen mode
  • Save and exit (ESC, :wq, ENTER) Install dependencies:
composer install
npm install
Enter fullscreen mode Exit fullscreen mode

(Check Node/NPM versions: node -v, npm -v. Install if missing.)
Build assets:

npm run build
Enter fullscreen mode Exit fullscreen mode

✅ Site is now live with the new repository.

Step 5: Configure GitHub Actions Deployment

# Check private key content
cat ~/.ssh/id_rsa_company

# Add public key to authorized_keys
cat ~/.ssh/id_rsa_company.pub >> ~/.ssh/authorized_keys

# Verify authorized_keys
cat ~/.ssh/authorized_keys
Enter fullscreen mode Exit fullscreen mode
  • Copy the key and add it to GitHub Actions → SSH Key Secret After this, any commit, push, or release can trigger deployment to the VPS automatically.

Once this is set up, your live site is fully connected to the new GitHub repository, and all future changes—commits, pushes, or releases—will automatically deploy to your VPS via GitHub Actions. ✅

Tip: Always test deployments on a staging environment first if possible, to ensure everything works as expected before affecting your live site.

HAPPY CODING! 🚀

Top comments (0)