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:
Example Usage
Methods
add
Stages a file or files for commit. If all is True, stages all changes.
File path to add (ignored if all=True).
If True, adds all changes instead of a single file.
branch
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.
The name of the new branch.
Whether to create and checkout the branch.
checkout
Clones a repository into target_dir
. If ref
is provided, it checks out that specific branch/tag.
The local directory for the clone.
The Git ref (branch, tag) to clone. Defaults to "" (clone the default branch).
If True, this indicates the intention to create a new branch, but is not currently used in the command.
clone
An alias for checkout, providing the same behavior for consistency.
The local directory for the clone.
The Git ref (branch, tag) to clone. Defaults to "" (clone the default branch).
If True, this indicates the intention to create a new branch, but is not currently used in the command.
commit
Commits staged changes with a given commit message.
The commit message.
init
Initializes a new Git repository locally.
pull
Pulls from the repository specified by the class’s constructed remote URL. It runs git pull origin=url HEAD.
push
Pushes the current HEAD to the remote. If publish is True, it pushes with the -u origin HEAD flag, setting the upstream branch.
Whether to set upstream on push.