⚠️ 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
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
- Paste the copied key into GitHub → Settings → Deploy Keys
- Check Allow write access
Step 3: Configure Multiple SSH Keys
nano ~/.ssh/config
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
- Save and exit (CTRL + O, ENTER, CTRL + X) Test the connection:
ssh -T git@github-company
Expected output:
Hi **YOUR_COMPANY**! You've successfully authenticated, but GitHub does not provide shell access.
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
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**
- Save and exit (ESC, :wq, ENTER) Install dependencies:
composer install
npm install
(Check Node/NPM versions: node -v, npm -v. Install if missing.)
Build assets:
npm run build
✅ 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
- 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)