You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

现有GitHub仓库通过SSH部署到Bluehost生产服务器的流程咨询

Automated Deployment to Bluehost via SSH (With Existing GitHub Repository)

Absolutely, this setup is totally feasible—and you can absolutely keep your existing GitHub repository while adding automated deployments to Bluehost. Your current workflow with GitHub Desktop will only get more efficient, no need to ditch anything you're already using. Let’s break this down step by step, tailored to your setup.

1. Is This Feasible?

100% yes. Git supports multiple remote repositories, so you can configure your local repo to push changes to both GitHub (your existing origin remote) and Bluehost simultaneously. No more manual FTP drag-and-drop—one push does it all.

2. Will My Existing GitHub Repository Affect the Deployment?

Nope, not at all. Your GitHub repo will stay intact, with all its commit history, PRs, issues, and collaboration features unchanged. We’re just adding an extra "destination" for your pushes; GitHub remains your primary code repository, and Bluehost becomes your deployment target.

3. Step-by-Step Setup for Your Existing GitHub Repo

Let’s get this configured, starting with the Bluehost server side, then your local repo.

3.1 Prepare Bluehost for Git Deployment

First, log into your Bluehost server via SSH (use Terminal on Mac/Linux, PuTTY or Windows Terminal on Windows—you can find your SSH credentials in Bluehost’s cPanel under "SSH Access").

  • Navigate to your user’s home directory (not your website’s public root, we’ll create a bare repo here):
    cd ~
    
  • Create a bare Git repository (this acts as a "hub" to receive pushes, since we don’t want a working directory in your public web folder):
    mkdir your-project-name-deploy.git
    cd your-project-name-deploy.git
    git init --bare
    
  • Create a post-receive hook—this script will automatically sync the pushed code to your website’s public root folder after you push to the bare repo:
    nano hooks/post-receive
    
    Paste this code (replace /home/your-bluehost-username/public_html with your actual website root path—you can find this in cPanel under "File Manager"):
    #!/bin/sh
    git --work-tree=/home/your-bluehost-username/public_html --git-dir=/home/your-bluehost-username/your-project-name-deploy.git checkout -f master
    
  • Save the file (in nano, press Ctrl+O, then Enter, then Ctrl+X), then give it execution permissions:
    chmod +x hooks/post-receive
    

3.2 Add Bluehost as a Remote to Your Local Repo

Open your project in GitHub Desktop, then click Repository > Open in Terminal (or just navigate to your local repo folder in Terminal manually).

  • Add Bluehost as a new remote repository:
    git remote add bluehost ssh://your-bluehost-username@your-domain.com/home/your-bluehost-username/your-project-name-deploy.git
    
    For example, if your Bluehost username is jpsweeney94 and your domain is example.com, it would look like:
    git remote add bluehost ssh://jpsweeney94@example.com/home/jpsweeney94/your-project-name-deploy.git
    
  • Verify the remote was added correctly:
    git remote -v
    
    You should see two entries: origin (pointing to your GitHub repo) and bluehost (pointing to your Bluehost bare repo).

3.3 Configure Automatic Pushes to Both Remotes

You’ve got two options here—pick whichever fits your workflow best:

Option 1: Push to Both Remotes With a Single Command

If you don’t mind running a terminal command occasionally (or you can even create a bash alias for it), use this:

git push origin master && git push bluehost master

This will push to GitHub first, then Bluehost.

Option 2: Make GitHub Desktop Push to Both Remotes Automatically

To make the "Push" button in GitHub Desktop send code to both GitHub and Bluehost:

# Add your GitHub repo as a push target for origin
git remote set-url --add --push origin git@github.com:your-github-username/your-github-repo.git
# Add Bluehost as an additional push target for origin
git remote set-url --add --push origin ssh://your-bluehost-username@your-domain.com/home/your-bluehost-username/your-project-name-deploy.git

Now, whenever you click "Push" in GitHub Desktop, Git will automatically push to both remotes in the background. You’ll see GitHub’s push status in the app, but Bluehost will get the updates too.

3.4 Test the Workflow

  • Make a small change to a file in your local repo, commit it in GitHub Desktop.
  • Click "Push" as you normally would.
  • Log into Bluehost’s File Manager or use SSH to check your public_html folder—your updated file should be there!

4. Quick Troubleshooting Tips

  • SSH Connection Errors: Make sure your local SSH public key is added to Bluehost’s authorized_keys file. You can do this via Bluehost’s cPanel under "SSH Access" > "Manage SSH Keys".
  • Hook Not Syncing Files: Double-check the paths in your post-receive script—they need to be absolute paths (starting with /). Also confirm the script has execution permissions (chmod +x hooks/post-receive).
  • Wrong Branch Deployed: If you use a branch other than master, update the checkout -f master line in the hook to match your branch name (e.g., checkout -f main).

内容的提问来源于stack exchange,提问作者jpsweeney94

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 18:23:11