GitHub Integration
Connect your GitHub repositories to enable version-controlled metadata management, automated drift detection, and seamless deployments between Git and HubSpot.
Overview
GitHub integration allows you to:
- Store metadata in Git: Version-control your HubSpot metadata
- Compare Git to HubSpot: See differences between your repository and portals
- Deploy from Git: Push metadata changes from Git to HubSpot
- Automated drift detection: Monitor when portals diverge from Git
- Backup to Git: Automatically commit portal changes to your repository
Prerequisites
Before connecting GitHub, you need:
- GitHub Account: Personal or organization account
- Personal Access Token (PAT): Token with repository access
- Repository: Existing repository or create a new one
- Permissions:
git:createpermission in your workspace
Creating a Personal Access Token
Classic Token (Recommended)
- Go to GitHub → Settings → Developer settings
- Click Personal access tokens → Tokens (classic)
- Click Generate new token (classic)
- Configure the token:
- Note: "HubSpot Deploy Integration"
- Expiration: Choose duration (90 days recommended)
- Scopes: Select
repo(full control of private repositories)
- Click Generate token
- Copy the token immediately (you won't see it again)
Fine-Grained Token (Alternative)
- Go to GitHub → Settings → Developer settings
- Click Personal access tokens → Fine-grained tokens
- Click Generate new token
- Configure the token:
- Token name: "HubSpot Deploy Integration"
- Expiration: Choose duration
- Repository access: Select specific repositories
- Permissions:
- Contents: Read and write
- Metadata: Read-only
- Click Generate token
- Copy the token immediately
⚠️ Security Note: Store your token securely. Never commit it to Git or share it publicly.
Connecting GitHub Account
Step 1: Connect Your GitHub Account
- Navigate to Connections screen
- In the Git Repositories column, click Connect Git
- In the modal:
- (Optional) Enter Account Name Alias (e.g., "My Git Account")
- Paste your Personal Access Token
- Click Connect Git
The system will:
- Validate the token
- Fetch your GitHub username
- Store the connection securely (token is encrypted)
- Enable repository management
Step 2: Add a Repository
After connecting your GitHub account:
- Click Add Repo button
- In the modal:
- Select GitHub Account from dropdown
- Enter Repository in
owner/repoformat (e.g.,acme/hubspot-metadata) - Enter Branch (default:
main)
- Click Add Repository
The system will:
- Validate repository access
- Create repository record
- Enable the repository for comparisons and deployments
Repository Format
Directory Structure
Your repository should follow this structure:
my-hubspot-metadata/
├── workflows/
│ ├── workflow-1.json
│ └── workflow-2.json
├── forms/
│ ├── contact-form.json
│ └── newsletter-form.json
├── emails/
│ ├── welcome-email.json
│ └── follow-up-email.json
├── custom_objects/
│ └── my-object.json
└── properties/
├── contact-properties.json
└── company-properties.json
Metadata File Format
Each metadata item is stored as a JSON file:
{
"id": "12345",
"name": "Contact Form",
"type": "form",
"properties": {
"formType": "HUBSPOT",
"submitText": "Submit",
"redirect": "https://example.com/thank-you"
},
"fields": [
{
"name": "email",
"label": "Email Address",
"fieldType": "email",
"required": true
}
]
}
Note: The exact structure depends on the metadata type. Use the Backup feature to see the format for each type.
Using GitHub Integration
Comparing Git to HubSpot
Use case: See what's different between your repository and portal
- Navigate to Comparisons screen
- Click New Comparison
- Select:
- Source: Your Git repository
- Target: HubSpot portal
- Click Initialize Comparison
- Wait for population to complete
- Review differences in the diff viewer
Deploying from Git to HubSpot
Use case: Push metadata changes from Git to your portal
- Create a comparison (Git → HubSpot)
- Review the differences
- Select items to deploy
- Click Deploy Selected
- Choose deployment mode (Auto or Assisted)
- Monitor deployment progress
See Deployments for detailed deployment instructions.
Backing Up HubSpot to Git
Use case: Commit portal changes to your repository
- Navigate to Backups screen
- Select your HubSpot connection
- Choose metadata types to backup
- Select Git Repository as destination
- Click Start Backup
The system will:
- Extract metadata from HubSpot
- Format as JSON files
- Commit to your repository
- Push to the specified branch
See Backups for more details.
Automated Drift Detection
Use case: Monitor when portal diverges from Git
- Navigate to Instance Observer for your portal
- Go to Drift Detection tab
- Click Configure Drift Detection
- Select:
- Git Repository as source
- Schedule (hourly, daily, weekly)
- Click Save
The system will:
- Automatically compare Git to portal on schedule
- Create drift reports when differences are found
- Send email notifications (if configured)
See Drift Detection for more details.
Managing Repositories
Viewing Repository Details
- Navigate to Connections screen
- Find the repository in the Git Repositories column
- Click on the repository card
This shows:
- Repository name and branch
- Connected GitHub account
- Recent comparisons using this repository
- Deployment history
Removing a Repository
⚠️ Warning: Removing a repository will:
- Delete the repository record
- Preserve existing comparisons and deployments
- Disable drift detection using this repository
To remove:
- Navigate to repository details
- Click Remove Repository
- Confirm deletion
Updating Repository Branch
To change the branch:
- Remove the existing repository
- Add it again with the new branch
Note: This creates a new repository record. Existing comparisons will reference the old record.
Multiple GitHub Accounts
You can connect multiple GitHub accounts to access repositories from different organizations:
- Connect first account: Connect Git → Enter PAT
- Connect second account: Connect Git → Enter different PAT
- When adding repositories, select the appropriate account
Use cases:
- Personal and work accounts
- Multiple organizations
- Different permission levels
Permissions
GitHub integration requires workspace permissions:
| Action | Required Permission |
|---|---|
| Connect GitHub account | git:create |
| Add repository | git:create |
| View repositories | git:read |
| Remove repository | git:delete |
| Deploy from Git | deployments:create |
Note: Workspace admins have all permissions by default.
Troubleshooting
"Failed to connect" Error
Problem: Cannot connect GitHub account
Possible causes:
- Invalid or expired token
- Insufficient token permissions
- Network connectivity issues
Solution:
- Verify token is copied correctly (no extra spaces)
- Check token hasn't expired
- Ensure token has
reposcope (classic) orContents: Read and write(fine-grained) - Generate a new token if needed
"Repository not found" Error
Problem: Cannot add repository
Possible causes:
- Repository name format incorrect
- Token doesn't have access to repository
- Repository doesn't exist
- Private repository without proper permissions
Solution:
- Verify format is
owner/repo(e.g.,acme/metadata) - Check repository exists on GitHub
- Ensure token has access to the repository
- For organization repos, verify token has organization access
"Failed to fetch metadata" During Comparison
Problem: Comparison fails when reading from Git
Possible causes:
- Branch doesn't exist
- No metadata files in repository
- Invalid JSON format in files
- Token permissions revoked
Solution:
- Verify branch exists in repository
- Check repository has metadata files in correct format
- Validate JSON files are properly formatted
- Re-authenticate GitHub connection if token expired
Drift Detection Not Running
Problem: Scheduled drift checks aren't executing
Possible causes:
- Repository connection removed
- Token expired
- Worker not running
- Schedule not configured
Solution:
- Check repository still exists in Connections
- Verify GitHub connection is active
- Re-configure drift detection schedule
- Check drift reports for error messages
Deployment from Git Fails
Problem: Cannot deploy metadata from Git to HubSpot
Possible causes:
- HubSpot connection expired
- Insufficient HubSpot scopes
- Invalid metadata format in Git
- Dependency issues
Solution:
- Re-authenticate HubSpot connection
- Check HubSpot connection has required scopes (see Scopes)
- Validate metadata JSON files match expected format
- Review deployment logs for specific errors
Best Practices
Token Management
- Use descriptive names: Name tokens clearly (e.g., "HubSpot Deploy - Production")
- Set expiration: Use 90-day expiration and rotate regularly
- Limit scope: Use fine-grained tokens for specific repositories when possible
- Revoke unused tokens: Remove tokens you're no longer using
Repository Organization
- One repo per environment: Separate repos for production, staging, development
- Use branches: Use Git branches for different environments or versions
- Commit messages: Write clear commit messages when backing up to Git
- Review changes: Always review Git diffs before deploying
Workflow
- Git as source of truth: Keep Git as the authoritative source for metadata
- Regular backups: Schedule automatic backups from HubSpot to Git
- Drift monitoring: Enable drift detection to catch manual portal changes
- Test deployments: Test Git deployments in staging before production
Security
- Never commit tokens: Don't store PATs in your repository
- Use .gitignore: Exclude sensitive files from Git
- Rotate tokens: Change tokens every 90 days
- Audit access: Regularly review who has access to repositories
Common Workflows
Initial Setup: Portal to Git
Goal: Start version-controlling an existing portal
- Connect GitHub account
- Create new repository on GitHub
- Add repository in HubSpot Deploy
- Create backup: Portal → Git
- Verify files committed to repository
- Enable drift detection
Continuous Deployment: Git to Portal
Goal: Deploy metadata changes from Git
- Make changes to metadata files in Git
- Commit and push to repository
- Create comparison: Git → Portal
- Review differences
- Deploy selected items
- Verify changes in HubSpot
Environment Promotion: Staging to Production
Goal: Promote tested changes to production
- Deploy changes to staging portal
- Test thoroughly in staging
- Backup staging portal to Git (staging branch)
- Create comparison: Git (staging) → Production Portal
- Review and deploy to production
Related Features
- Comparisons: Compare Git to HubSpot
- Deployments: Deploy from Git to portals
- Backups: Backup portals to Git
- Drift Detection: Monitor portal changes
- Connections: Manage all connections
Next Steps
- Learn about creating comparisons with Git repositories
- Set up automated drift detection for your portals
- Configure backup schedules to Git