GitTool provides methods to execute common Git operations on local repositories.
Installation
Install the Git dependency:
Constructor
Optional API key for MCP server usage
Methods
clone
Clone a repository from a remote URL.
Git repository URL (HTTPS or SSH)
Local path where repository will be cloned
Returns: Success message or error
pull
Pull changes from the remote repository.
Path to local Git repository
Returns: Success message or error
commit
Commit all changes in the repository.
Path to local Git repository
Returns: Confirmation with commit message
push
Push commits to the remote repository.
Path to local Git repository
Returns: Success message or error
status
Get the current status of the repository.
Path to local Git repository
Returns: Git status output
Usage
With Agentor agent
from agentor import Agentor
from agentor.tools import GitTool
git_tool = GitTool()
agent = Agentor(
name="Git Assistant",
model="gpt-4o-mini",
tools=[git_tool]
)
result = agent.run("Check the status of /path/to/repo")
print(result)
Clone a repository
from agentor.tools import GitTool
git = GitTool()
result = git.clone(
repo_url="https://github.com/CelestoAI/agentor.git",
to_path="./agentor"
)
print(result) # Cloned https://github.com/... to ./agentor
Commit and push workflow
# Check status
status = git.status("/path/to/repo")
print(status)
# Commit changes (automatically stages all changes)
result = git.commit(
repo_path="/path/to/repo",
message="Add new feature"
)
print(result) # Committed with message: Add new feature
# Push to remote
result = git.push("/path/to/repo")
print(result) # Successfully pushed changes.
Pull updates
# Pull latest changes from remote
result = git.pull("/path/to/repo")
print(result) # Successfully pulled changes.
Notes
The commit method automatically stages all changes (equivalent to git add -A) before committing.
GitTool requires appropriate Git credentials for push/pull operations. Make sure SSH keys or credential helpers are configured.
Error handling
# Invalid repository path
result = git.status("/invalid/path")
print(result) # Error getting status: ...
# Push without remote configured
result = git.push("/path/to/repo")
print(result) # Error pushing changes: ...
Source reference
src/agentor/tools/git.py:25