Git Product home page Git Product logo

python-git-wrapper's Introduction

Git Wrapper

The Simple Python Git Wrapper

PyPI version

This library is a simple git wrapper which let you perform many operations on any git repository in a powerful and simple way.

Requirements

This library has been tested python >= 3.7, 3.8 and you need to have installed Git > 2.22.0

Getting Started

The library is pretty simple, you only need to indicate where your repository is or create a new one.

from python_git_wrapper import Repository

repository = Repository('.') # Path of your git repository. It could be relative to your project or absolute

Or if the repository doesn't exist yet

repository = Repository('.', create=True)

Adding files:

repository.add_files('path to any file')

Committing changes:

repository.commit('commit message')

Finally, pushing them:

repository.push()

Components

The library is divided in 3 main components.

  • Git Service: Object which contains all the data to communicate with the git process properly.

    • NOTE: If you don't have configured the path of the git binary in your path. Execute the next command: GitService.singleton('git path'')
  • Repository: It will be your entry point, which you will interact to provide an retrieve all the information. It is a reference to the repository you want to work on.

  • Git Elements:

    • Commit: Containing all the relevant information about any commit

    • Branch: Contains the name of the branch

    • Status: Object which structure all the changes in your working directory

API Overview

Small overview about the capabilities of this library. All this methods and attributes are accesible by the repository object.

Method Description Return
build Create or init a new git repository Repository
commit Commit the staged changes Status
status Retrieve the Status of the Working Directory Status
push Push Changes to remote repository Status
pull Pull changes to remote repository Status
checkout Change HEAD reference Status
create_branch Create a new branch, go there if necessary Branch
merge_branches Merge two branches. Support different merge modes Branch
add_remote Add a new remote repository Status
remove_remote Remove a remote repository Status
execute execute any git command in the repository str
revert_last_commit Generate a new commit reverting the previous one Commit
change_last_commit_message Rewrite the previous commit message Commit
get_commit Retrieve Commit by hash in the repository Commit
get_commit_by_position Retrieve Commit by position in the current branch Commit
get_commit_children Retrieve Commits that HEAD contributed towards Commit
get_commit_parents Retrieve Commits that contributed towards HEAD Commit
get_branches_by_commit Retrieve all the branches which contain one specific commit Commit
Property Description Return
branches List of your local branches List[Branch]
current_branch The branch where it is currently the repository Branch
remote List of your remote repository names List[str]
last_commit The last commit in your repository Commit

Detailed API Specification Here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.