Certainly! Here’s a comprehensive solution to the Laracasts question:
Solution:
Yes, it's true that Laravel Forge has recently made a change regarding how it sets up git remotes on new servers.
Previously, Forge would typically set the origin remote using the SSH format, like:
[email protected]:your-username/your-repo.git
However, Forge rolled out an update and now, by default, uses the HTTPS format:
https://github.com/your-username/your-repo.git
Why the Change?
- SSH keys can be tricky: Some users had trouble setting up SSH keys correctly between the server and git provider (like GitHub/GitLab), often causing deployments to fail.
- HTTPS is easier: With HTTPS, Forge can use a deployment token (or sometimes just username/password for private repos) for authentication.
Why Are My Deployments Failing?
When the remote URL is set to HTTPS and authentication isn’t set up (like cached credentials, or GitHub deploy tokens), git pull will fail—especially for private repos.
How To Fix
Option 1: Switch Back To SSH
If you prefer the old way, you can switch the remote to SSH like this:
git remote set-url origin [email protected]:your-username/your-repo.git
Make sure your server’s ~/.ssh/id_rsa.pub is added to your repo’s deploy keys on GitHub/GitLab.
Option 2: Fix HTTPS Authentication
If you decide to keep the HTTPS remote:
- Use a Personal Access Token: Create a deploy token on GitHub/GitLab.
- Set up a
.netrcfile (in your deploy user’s home directory):machine github.com login your-github-username password your-deploy-token - Or, set up Git credentials caching (less secure).
Option 3: Use SSH Deploy Keys (Recommended)
This method is more secure and consistent for automated server environments:
- Generate a new SSH key on the server:
ssh-keygen -t ed25519 -C "[email protected]" - Add the public key (
~/.ssh/id_ed25519.pub) to your git provider as a deploy key under the repo settings. - Switch origin to SSH as in Option 1.
Summary:
Forge’s recent switch to HTTPS remotes by default is normal. It’s up to you whether to use HTTPS (with a token/.netrc) or switch back to SSH (with deploy keys). For most deployments, SSH deploy keys are the more secure and reliable option.
Let me know if you need step-by-step setup instructions!