# What Git Operations Are Supported Through ML Intern's GitHub Integration Tools?

> Discover the Git operations ML Intern supports on Hugging Face Hub repositories including branch management tagging pull requests and more Learn about GitHub exploration utilities for public repositories.

- Repository: [Hugging Face/ml-intern](https://github.com/huggingface/ml-intern)
- Tags: api-reference
- Published: 2026-04-24

---

**ML Intern supports full Git workflows—including branch management, tagging, pull requests, and repository creation—on Hugging Face Hub repositories via the `hf_repo_git` tool, while providing read-only GitHub exploration utilities for discovering and reading public repository contents.**

ML Intern provides a comprehensive suite of Git integration tools that enable agents to interact with both Hugging Face Hub repositories and public GitHub repositories. These tools are implemented as asynchronous handlers in the `agent/tools/` directory, allowing automated workflows for version control tasks ranging from branch creation to pull request management.

## HF Repo Git Tool: Full Git Workflows on Hugging Face Hub

Implemented in [`agent/tools/hf_repo_git_tool.py`](https://github.com/huggingface/ml-intern/blob/main/agent/tools/hf_repo_git_tool.py), this asynchronous tool wraps the Hugging Face Hub API to provide comprehensive version control capabilities for models, datasets, and Spaces.

### Branch and Tag Management

The tool supports complete reference management operations:

- **`create_branch`**: Creates a new branch from a specified revision (defaults to `main`)
- **`delete_branch`**: Removes an existing branch
- **`list_refs`**: Enumerates all branches and tags in the repository
- **`create_tag`**: Creates a version tag on a specific revision
- **`delete_tag`**: Removes an existing tag

### Pull Request and Discussion Workflows

Agents can execute complete PR lifecycle management through these operations:

- **`create_pr`**: Opens a draft pull request or discussion
- **`list_prs`**: Retrieves PRs with optional status filtering (`open`, `closed`, `all`)
- **`get_pr`**: Fetches detailed information for a specific PR
- **`merge_pr`**: Merges an approved pull request
- **`close_pr`**: Closes a PR or discussion
- **`comment_pr`**: Adds commentary to an existing PR
- **`change_pr_status`**: Modifies PR state, such as converting drafts to open, ready-to-review status

### Repository Lifecycle Management

Programmatic repository administration is handled via:

- **`create_repo`**: Initializes new model, dataset, or Space repositories
- **`update_repo`**: Modifies repository settings including privacy controls and gated access configurations

All operations return a tuple of `(formatted_output, success_flag)`, where the formatted output is a human-readable markdown string suitable for direct user presentation.

## GitHub Repository Exploration Tools

Unlike the HF Repo Git Tool, these read-only utilities target public GitHub repositories for discovery and code inspection.

### Repository Discovery

[`agent/tools/github_list_repos.py`](https://github.com/huggingface/ml-intern/blob/main/agent/tools/github_list_repos.py) implements `github_list_repos_handler`, which enumerates repositories for a specified user or organization. The handler accepts sorting parameters (`stars`, `forks`, `updated`, `created`) and result limiting to surface the most relevant repositories.

### Code Search and Retrieval

- **[`agent/tools/github_find_examples.py`](https://github.com/huggingface/ml-intern/blob/main/agent/tools/github_find_examples.py)**: Searches a repository's file tree for example scripts matching specific keywords, returning direct GitHub URLs to matching files.
- **[`agent/tools/github_read_file.py`](https://github.com/huggingface/ml-intern/blob/main/agent/tools/github_read_file.py)**: Retrieves the raw contents of specific files from public repositories, typically invoked after `github_find_examples` to read discovered implementation details.

These tools enable agents to locate reference implementations on GitHub before applying modifications via the HF Repo Git Tool on Hugging Face repositories.

## Practical Code Examples

The following snippets demonstrate how agents invoke these tools via their async handlers.

### Listing Top-Starred Organization Repositories

```python
from agent.tools.github_list_repos import github_list_repos_handler

args = {
    "owner": "huggingface",
    "owner_type": "org",
    "sort": "stars",
    "order": "desc",
    "limit": 5,
}
output, ok = await github_list_repos_handler(args)
print(output)   # formatted markdown list of top‑5 repos

```

### Creating a Feature Branch

```python
from agent.tools.hf_repo_git import hf_repo_git_handler

args = {
    "operation": "create_branch",
    "repo_id": "username/my-model",
    "branch": "experiment-v2",
    "from_rev": "main",       # optional, defaults to main

}
output, ok = await hf_repo_git_handler(args)
print(output)   # "**Branch created:** experiment‑v2\nhttps://huggingface.co/username/my-model/tree/experiment-v2"

```

### Managing Draft Pull Requests

```python

# Create draft PR

pr_args = {
    "operation": "create_pr",
    "repo_id": "username/my-model",
    "title": "Add new tokenizer config",
}
out, ok = await hf_repo_git_handler(pr_args)
print(out)   # shows draft PR number and URL

# Publish the PR once ready

publish_args = {
    "operation": "change_pr_status",
    "repo_id": "username/my-model",
    "pr_num": 1,               # replace with actual PR number

    "new_status": "open",
}
out, ok = await hf_repo_git_handler(publish_args)
print(out)   # "**PR #1 status changed to open** …"

```

### Tagging Releases and Listing References

```python

# Tag creation

tag_args = {
    "operation": "create_tag",
    "repo_id": "username/my-model",
    "tag": "v1.0",
    "revision": "main",
}
out, ok = await hf_repo_git_handler(tag_args)
print(out)

# List branches & tags

list_args = {"operation": "list_refs", "repo_id": "username/my-model"}
out, ok = await hf_repo_git_handler(list_args)
print(out)   # Shows a markdown block with branches and tags

```

### Creating a Private Space Repository

```python
create_args = {
    "operation": "create_repo",
    "repo_id": "my-new-space",
    "repo_type": "space",
    "private": True,
    "space_sdk": "gradio",    # required for spaces

}
out, ok = await hf_repo_git_handler(create_args)
print(out)

```

## Summary

- The `hf_repo_git` tool in [`agent/tools/hf_repo_git_tool.py`](https://github.com/huggingface/ml-intern/blob/main/agent/tools/hf_repo_git_tool.py) provides comprehensive Git operations for Hugging Face repositories, including branch/tag management, full PR workflows, and repository creation.
- GitHub integration is handled by separate read-only tools: [`github_list_repos.py`](https://github.com/huggingface/ml-intern/blob/main/github_list_repos.py), [`github_find_examples.py`](https://github.com/huggingface/ml-intern/blob/main/github_find_examples.py), and [`github_read_file.py`](https://github.com/huggingface/ml-intern/blob/main/github_read_file.py) for repository discovery and file inspection.
- All handlers are asynchronous and return structured responses with success indicators and formatted output for direct user presentation.
- Tool registration and routing occurs in [`agent/core/tools.py`](https://github.com/huggingface/ml-intern/blob/main/agent/core/tools.py), which maps operation names to their respective handler functions.

## Frequently Asked Questions

### Can ML Intern push commits directly to GitHub repositories?

No. The GitHub integration tools are read-only. As implemented in [`agent/tools/github_read_file.py`](https://github.com/huggingface/ml-intern/blob/main/agent/tools/github_read_file.py) and related modules, ML Intern performs write operations (commits, branches, PRs) exclusively on Hugging Face Hub repositories via the `hf_repo_git` tool, while GitHub repositories can only be explored, listed, and read.

### What is the difference between `create_pr` and `change_pr_status` in the HF Repo Git Tool?

`create_pr` initializes a pull request as a draft by default, allowing agents to upload files and prepare changes before publication. `change_pr_status` modifies the PR state—such as converting a draft to an open, ready-to-review PR—enabling controlled, multi-step submission workflows without immediate public visibility.

### How does the `list_refs` operation differ from `github_list_repos`?

`list_refs` operates on a specific Hugging Face repository via [`agent/tools/hf_repo_git_tool.py`](https://github.com/huggingface/ml-intern/blob/main/agent/tools/hf_repo_git_tool.py) to enumerate its internal branches and tags. In contrast, `github_list_repos` queries GitHub's API through [`agent/tools/github_list_repos.py`](https://github.com/huggingface/ml-intern/blob/main/agent/tools/github_list_repos.py) to enumerate top-level repositories belonging to a user or organization, with optional sorting by stars or update recency.

### Which file handles the registration of these Git tools with the ML Intern agent?

All tool handlers are registered in **[`agent/core/tools.py`](https://github.com/huggingface/ml-intern/blob/main/agent/core/tools.py)**, which maps operation names to their respective handler functions (e.g., `hf_repo_git_handler`, `github_list_repos_handler`) and integrates them into the agent's routing mechanism for automated invocation.