> ## Documentation Index
> Fetch the complete documentation index at: https://codegeninc-tawsif-change-additional-tools-to-tools.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Git Operations

Many workflows require Git operations. Codegen provides a high-level API for common Git operations through the [Codebase](/api-reference/core/Codebase) class, including:

* [Codebase.git\_commit(...)](/api-reference/core/Codebase#git_commit)
* [Codebase.checkout(...)](/api-reference/core/Codebase#checkout)

## Committing Changes to Git

You can commit changes to Git using the [Codebase.git\_commit(...)](/api-reference/core/Codebase#git_commit):

```python
# Make some changes and call `commit()` to sync them to disk
codebase.functions[0].rename('foo')
codebase.commit()

# Commit all staged changes to git with a message
commit = codebase.git_commit("feat: update function signatures")

# You can also verify the commit (runs pre-commit hooks)
commit = codebase.git_commit("feat: update signatures", verify=True)

# The method returns the commit object if changes were committed, None otherwise
if commit:
    print(f"Created commit: {commit.hexsha}")
```

<Note>
  `git_commit` will only commit changes that have been synced to the filesystem
  by calling [Codebase.commit()](/api-reference/core/Codebase#commit). See
  [Commit and Reset](/building-with-codegen/commit-and-reset) for more
  details.
</Note>

## Checking Current Git State

Codegen provides properties to check the current Git state:

```python
# Get the default branch (e.g. 'main' or 'master')
default = codebase.default_branch
print(f"Default branch: {default}")

# Get the current commit
current = codebase.current_commit
if current:
    print(f"Current commit: {current.hexsha}")
```

## Checking Out Branches and Commits

The [Codebase.checkout(...)](/api-reference/core/Codebase#checkout) method allows you to switch between branches and commits.

This will automatically re-parse the codebase to reflect the new state.

```python
# Checkout a branch
result = codebase.checkout(branch="feature/new-api")

# Create a new branch if it doesn't exist
result = codebase.checkout(branch="feature/new-api", create_if_missing=True)

# Checkout a specific commit
result = codebase.checkout(commit="abc123")

# Checkout and pull from remote
result = codebase.checkout(branch="main", remote=True)
```
