feat: add GitTool for git operations#2112
feat: add GitTool for git operations#2112divyanshu-iitian wants to merge 1 commit intoOpenHands:mainfrom
Conversation
Add comprehensive git operations tool for agents enabling: - Repository management (init, clone, status) - Branch operations (create, checkout, list) - Change tracking (add, commit, diff, log) - Remote operations (push, pull, remote management) - Advanced features (stash, reset) Includes: - 14 git commands with full parameter support - Comprehensive test coverage (53 tests) - Example workflow automation - Security: subprocess-based with timeout protection Co-authored-by: openhands <openhands@all-hands.dev>
|
[Automatic Post]: I have assigned @enyst as a reviewer based on git blame information. Thanks in advance for the help! |
enyst
left a comment
There was a problem hiding this comment.
Hey @divyanshu-iitian , thank you for the contribution!
OpenHands agent does all git operations, using terminal tool most of the time: LLMs know git, gh, and other common tools very very well.
It's possible it would more difficult, not easier, for the LLM to use correctly a new tool that looks like git but it's a tool with a different format than the git command itself. 🤷
Did you encounter problems with OpenHands using git?
|
Hi @enyst, thank you for the detailed feedback! You're absolutely right. I made an assumption without validating the actual need - agents already use git perfectly through the terminal tool, and LLMs know git commands very well. A separate structured tool would indeed add unnecessary cognitive overhead. However, your feedback made me realize a different gap: agents currently cannot interact with GitHub's API (forking repos, creating PRs, managing issues, etc.). They can do local git operations but not remote GitHub operations. Would a GitHub API Integration Tool (using PAT tokens) be more useful? It could enable:
This would extend agent capabilities rather than duplicate existing terminal functionality. The git utilities in If this sounds useful, I'm happy to:
Or if you have other areas where contributions would be more valuable, I'd love to hear! Thank you for the learning opportunity. 🙏 |
enyst
left a comment
There was a problem hiding this comment.
However, your feedback made me realize a different gap: agents currently cannot interact with GitHub's API (forking repos, creating PRs, managing issues, etc.). They can do local git operations but not remote GitHub operations.
Would a GitHub API Integration Tool (using PAT tokens) be more useful? It could enable:
OpenHands agent can do that too! 😄
Just give it a PAT token. It can use gh or REST API, or if you configure it, the Github MCP.
Or if you have other areas where contributions would be more valuable, I'd love to hear! Thank you for the learning opportunity. 🙏
I suggest to use OpenHands for your needs. For example, via the CLI. See where it falls short of what you'd like, and please feel free to fix what you don't like.
It's the best way to improve it, and to learn while doing.
Summary
This PR adds GitTool, a comprehensive git operations tool that enables AI agents to autonomously perform version control tasks. The tool provides a structured interface to 14 essential git commands, allowing agents to manage repositories, branches, commits, and remotes as part of their workflows.
Key Features:
status,add,commit,push,pull,branch,checkout,diff,log,clone,init,reset,stash,remoteWhat's Included:
openhands-tools/openhands/tools/git/)tests/tools/git/)examples/01_standalone_sdk/40_git_workflow_automation.py)Architecture:
openhands.sdk.gitutilitiesUse Cases:
Checklist
40_git_workflow_automation.pytested successfully