Only in Mage Pro.Try our fully managed solution to access this advanced feature.
GitClient class provides a simple, Pythonic interface for performing Git operations within your Mage pipeline blocks. This is useful for automating version control workflows, such as:
- Automatically committing and pushing pipeline changes after successful runs
- Syncing code from remote repositories before execution
- Creating automated deployment pipelines
Prerequisites
Before usingGitClient, ensure you have configured Git settings in Mage through one of these methods:
- Git Sync Settings (legacy): Configure via Settings → Workspace → Sync data, or see the Git Sync guide
- Deployment Settings (Mage Pro): Configure via the Deploy app at
/apps/deploy
Quick Start
Basic Usage
Using Deployment Settings (Mage Pro)
Using GitClient in Pipeline Blocks
Data Exporter Block Example
The most common use case is pushing changes at the end of a pipeline:Data Loader Block Example
Pull latest changes before processing:GitClient Methods
Core Operations
add(files, flags)
add(files, flags)
Stage files for commit.Parameters:
files(str | List[str]): File path(s) to stage. Use'.'for all files.flags(List[str], optional): Git add flags (e.g.,['-A']to include deletions).
GitClient (for method chaining)commit(message, files)
commit(message, files)
Commit staged changes.Parameters:
message(str): The commit message.files(List[str], optional): Files to add before committing.
str - The commit hashpush(remote_name, branch_name, remote_branch_name)
push(remote_name, branch_name, remote_branch_name)
Push commits to the remote repository.Parameters:
remote_name(str, optional): Remote name. Defaults to configured remote.branch_name(str, optional): Local branch name. Defaults to current branch.remote_branch_name(str, optional): Remote branch name if different from local.
GitOperationResultpull(remote_name, branch_name)
pull(remote_name, branch_name)
Pull changes from the remote repository.Parameters:
remote_name(str, optional): Remote name. Defaults to configured remote.branch_name(str, optional): Branch name. Defaults to current branch.
GitOperationResultfetch()
fetch()
Fetch changes from the remote without merging.Returns:
GitOperationResultclone(sync_submodules)
clone(sync_submodules)
Clone the remote repository (replaces local content).Parameters:
sync_submodules(bool): Whether to also sync git submodules.
GitOperationResultConvenience Methods
add_commit_push(message, files, add_flags, remote_name, branch_name, remote_branch_name)
add_commit_push(message, files, add_flags, remote_name, branch_name, remote_branch_name)
Add, commit, and push changes in one operation. This is the recommended method for most use cases.Parameters:
message(str): The commit message.files(str | List[str]): File path(s) to stage. Default:'.'add_flags(List[str], optional): Git add flags (e.g.,['-A']).remote_name(str, optional): Remote name.branch_name(str, optional): Local branch name.remote_branch_name(str, optional): Remote branch name if different.
GitOperationResultsync(branch)
sync(branch)
Sync local repository with remote (fetch + reset —hard). Discards local changes.Parameters:
branch(str, optional): Branch to sync. Defaults to current branch.
GitOperationResultBranch Operations
switch_branch(branch, remote)
switch_branch(branch, remote)
Switch to a different branch.
merge_branch(branch, message)
merge_branch(branch, message)
Merge another branch into the current branch.
delete_branch(branch)
delete_branch(branch)
Delete a local branch.
Status Properties
status
status
Get comprehensive git status information.
current_branch
current_branch
Get the current branch name.
is_dirty
is_dirty
Check if there are uncommitted changes.
modified_files
modified_files
Get list of modified files.
branches
branches
Get list of local branches.
remotes
remotes
Get list of configured remotes.
unpushed_commits_count
unpushed_commits_count
Get number of commits not yet pushed to remote.
GitOperationResult
All Git operations return aGitOperationResult object with the following attributes:
| Attribute | Type | Description |
|---|---|---|
success | bool | Whether the operation succeeded |
message | str | Success or status message |
branch | str | The branch name involved |
remote | str | The remote name involved |
commit_hash | str | The commit hash (for commit/push operations) |
error | str | Error message if operation failed |
Method Chaining
GitClient supports method chaining for fluent API usage:
Advanced Examples
Conditional Push Based on Changes
Push to Multiple Branches
Pre-run Sync
Using the Built-in Git Push Template
Mage provides a built-in data exporter template for Git push operations. To add it to your pipeline:- Click Blocks in the top navigation
- Select Exporter
- Navigate to Version control → Git push

Setting Up Automated Git Push Jobs
You can automate Git push operations by creating a pipeline with a Git push block and configuring a trigger to run it on a schedule or in response to events.Step 1: Create a Git Push Pipeline
- Create a new pipeline (e.g.,
auto_git_push) - Add a Data Exporter block using the Git push template:
- Click Blocks → Exporter → Version control → Git push
- Configure the block with your desired settings:
Step 2: Create a Trigger
Navigate to your pipeline’s Triggers tab and create a new trigger:- Schedule Trigger
- API Trigger
For periodic backups (e.g., daily at midnight):
- Click + New trigger
- Select Schedule as the trigger type
- Configure the schedule:
- Name:
daily_git_backup - Frequency: Daily (or use Custom with cron:
0 0 * * *) - Start date: Set your desired start date
- Name:
- Click Save changes
| Pattern | Description |
|---|---|
0 * * * * | Every hour |
0 0 * * * | Daily at midnight |
0 9,18 * * 1-5 | Weekdays at 9 AM and 6 PM |
*/30 * * * * | Every 30 minutes |
For more details on trigger configuration, see the Pipeline Triggers documentation.
Troubleshooting
Authentication errors
Authentication errors
If you encounter authentication errors:
- Verify your Git settings are configured correctly
- For SSH: Ensure your SSH keys are properly set up
- For HTTPS: Verify your access token has the correct permissions
- Check that the remote URL is accessible from your Mage instance
Permission denied
Permission denied
If you see “Permission denied” errors:
- Check that your user has write access to the repository
- Verify the branch is not protected (or you have permission to push to protected branches)
- Ensure your OAuth token hasn’t expired
No changes to commit
No changes to commit
If
add_commit_push reports no changes:- Check
git.statusto see the current state - Verify files are not in
.gitignore - Use
git.modified_filesto see what files Git detects as changed
Related Resources
- Git Sync Configuration - Configuring Git sync settings
- Mage Pro Deployment Settings - Configure deployment settings for
use_deployment_settings=True