How to Set Up Git Pull Deployments with DeployHQ
Deploying your applications using Git Pull can be an efficient way to manage your deployments, especially when you want to maintain a Git repository on your server. In this guide, we'll walk you through setting up a Git Pull deployment using DeployHQ's Shell deployment target.
Prerequisites
Before getting started, ensure you have: - A DeployHQ account - A Git repository for your project - SSH access to your server - Git installed on your server
Step 1: Create a New Project
- Log in to your DeployHQ dashboard
- Click "New Project"
- Connect your repository
- Choose your repository provider (GitHub, Bitbucket, or GitLab)
Step 2: Set Up Your Shell Target
- Navigate to "Servers & Groups"
- Click "New Server"
- Select "Shell" as your deployment target, as explained here
- Fill in the following details:
- Server name
- Hostname (IP address or domain)
- Username
- Authentication method (SSH Key recommended)
- Remote path (where your repository is/will be located)
Step 3: Configure Git Pull Deployment
- Go to your project's "Configuration" tab
- Under "Deployment Settings," select "Git Pull" as your deployment method
- Add the following commands to your deployment script:
# Fetch latest changes
git fetch origin
# Reset to the deployed commit
git reset --hard %endrev%
# Clean up any untracked files
git clean -df
Keep in mind that your repository clone should already exist on your server.
A more straight forward approach would be just simply doing:
# Fetch latest changes
git fetch origin
# Reset to the latest commit on the branch
git pull %branch%
# Clean up any untracked files
git clean -df
Step 4: Set Up Repository on Your Server
- SSH into your server
- Navigate to your deployment directory
- Initialize Git repository (if not already present):
git init
git remote add origin <your-repository-url>
Step 5: Configure Deployment Settings
- Go to "Deployment Settings"
- Enable "Automatic Deployments" if desired
- Configure any build commands or additional scripts
- Set up your deployment branches
Step 6: Run Your First Deployment
- Click "Deploy" in your DeployHQ dashboard
- Select the branch you want to deploy
- Review the deployment configuration
- Click "Deploy Now"
Monitoring and Troubleshooting
- Monitor the deployment progress in real-time through the DeployHQ dashboard
- Check deployment logs for any issues
- Verify the deployed files on your server
- Ensure proper permissions are set on your deployment directory
Best Practices
- Always use SSH keys for authentication
- Keep your deployment scripts clean and maintainable
- Use environment variables for sensitive information
- Regularly check your deployment logs
- Set up notifications for deployment status
Additional Configuration Options
You can enhance your Git Pull deployments by:
- Adding post-deployment hooks
- Configuring environment variables
- Setting up deployment notifications
- Using deployment groups for multiple servers
Conclusion
Using DeployHQ's Shell target for Git Pull deployments provides a flexible and powerful way to manage your application deployments. This method gives you full control over the deployment process while maintaining the simplicity and reliability of Git-based deployments.
Remember to test your deployment configuration in a staging environment before implementing it in production. If you need any assistance, our support team is always here to help!
Need help setting up your Git Pull deployments? Contact our support team at support@deployhq.com or visit our documentation for more detailed guides and examples.