> ## Documentation Index
> Fetch the complete documentation index at: https://docs.blocks.team/llms.txt
> Use this file to discover all available pages before exploring further.

# git

The `git` module is a lightweight wrapper around common git operations. For more complex operations, you can execute commands directly using the `bash` utility. Credentials are automatically configured by default.

Default configuration:

```bash ~/.gitconfig theme={null}
user.name=BlocksOrg
user.email=bot@blocks.team
remote.origin.url=git@github.com:YourOrg/repo.git # The remote url of the repo which triggered the agent
```

## Example Usage

```python python theme={null}
from blocks import git

# Clone a repository
git.clone(target_dir="my-project", ref="develop")

# Make changes and commit
git.add(all=True)
git.commit("Update README.md")

# Push changes to origin
git.push(publish=True)
```

## Methods

### add

```python python theme={null}
git.add(file, all=False)
```

Stages a file or files for commit. If all is True, stages all changes.

**file** `string`

File path to add (ignored if all=True).

**all** `bool`

If True, adds all changes instead of a single file.

### branch

```python python theme={null}
git.branch(branch_name, checkout=False)
```

Creates a new branch by default. If checkout is True, creates and checks out (git checkout -b branch-name), otherwise just creates a branch with branch-name.

**branch\_name** `string`

The name of the new branch.

**checkout** `bool`

Whether to create and checkout the branch.

### checkout

```python python theme={null}
git.checkout(target_dir="repo", ref="", new_branch=False)
```

Clones a repository into `target_dir`. If `ref` is provided, it checks out that specific branch/tag.

**target\_dir** `string`

The local directory for the clone.

**ref** `string`

The Git ref (branch, tag) to clone. Defaults to "" (clone the default branch).

**new\_branch** `bool`

If True, this indicates the intention to create a new branch, but is not currently used in the command.

### clone

```python python theme={null}
git.clone(target_dir="repo", ref="", new_branch=False)
```

An alias for checkout, providing the same behavior for consistency.

**target\_dir** `string`

The local directory for the clone.

**ref** `string`

The Git ref (branch, tag) to clone. Defaults to "" (clone the default branch).

**new\_branch** `bool`

If True, this indicates the intention to create a new branch, but is not currently used in the command.

### commit

```python python theme={null}
git.commit(message)
```

Commits staged changes with a given commit message.

**message** `string`

The commit message.

### init

```python python theme={null}
git.init()
```

Initializes a new Git repository locally.

### pull

```python python theme={null}
git.pull()
```

Pulls from the repository specified by the class’s constructed remote URL. It runs git pull origin=url HEAD.

### push

```python python theme={null}
git.push(publish=False)
```

Pushes the current HEAD to the remote. If publish is True, it pushes with the -u origin HEAD flag, setting the upstream branch.

**publish** `bool`

Whether to set upstream on push.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.