I’m new to using Git with DigitalOcean and would like to know the best way to connect my local Git repository to my DigitalOcean server. What are some basic steps to set this up for deploying code directly from my local machine?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hey!
Usually you would use GitHub or GitLab, and on there setup an automation to push your code to your server whenever a pull request is merged.
But if you are specifically looking to set up code deployment from your local Git repository to a DigitalOcean Droplet directly without using GitHub, you could setup a
post-receive
hook to deploy code automatically whenever you push your code.Here is one way of doing this:
1. Set Up SSH Access to Your Droplet
2. Create a Dedicated Git User on the Droplet
git
user:git
user’s.ssh/authorized_keys
for secure access.3. Initialize a Bare Git Repository on the Droplet
git
user and create a bare repository for your app:4. Set Up a Post-Receive Hook for Deployment
/home/git/yourapp.git/hooks/
, create apost-receive
hook to deploy code automatically:5. Add the Droplet as a Remote in Your Local Repository
main
branch:6. Push Your Code to Deploy
This setup will allow you to deploy your application by pushing to the
droplet
remote.If you’re looking for a simpler way to deploy your application, consider DigitalOcean App Platform. It has built-in Git and GitHub integration for automated deployments, saving you from manual setup and handling deployments with every Git push to
main
. This is a great option if you want a streamlined, managed approach to code deployment!For more details, check out the DigitalOcean App Platform documentation.
Let me know if you need further help!
- Bobby