Questions tagged [gitpython]

GitPython is a python library used to interact with Git repositories

GitPython is a python library used to interact with Git repositories, providing object model access.

495 questions
9
votes
1 answer

GitPython: How can I access the contents of a file in a commit in GitPython

I am new to GitPython and I am trying to get the content of a file within a commit. I am able to get each file from a specific commit, but I am getting an error each time I run the command. Now, I know that the file exist in GitPython, but each…
9
votes
2 answers

Get the diff details of first commit in GitPython

In GitPython, I can iterate separately the diff information for every change in the tree by calling the diff() method between different commit objects. If I call diff() with the create_patch=True keyword argument, a patch string is created for every…
osolmaz
  • 1,873
  • 2
  • 24
  • 41
9
votes
1 answer

How to write unit tests for GitPython clone/pull functions?

I have a python project that is using GitPython to perform clone and pull functions against a remote Git repository. As a simple example: import git from git import Git from git import Repo def clone_and_checkout(full_dir, git_url, repo_ver): …
Mierdin
  • 359
  • 1
  • 5
  • 14
9
votes
1 answer

git-clean with GitPython

Is there any way to do something like git clean -d -x -f using GitPython? I need to reset working directories and want to get rid of all unversioned files without deleting the whole folder (except for .git) and checking out again.
Paddre
  • 798
  • 1
  • 9
  • 19
9
votes
2 answers

How to get count of unpublished commit with GitPython?

With git status I can get information about count of unpublished commits: » git status # On branch master # Your branch is ahead of 'origin/master' by 2 commits. # (use "git push" to publish your local commits) # nothing to commit,…
Gr1N
  • 1,337
  • 3
  • 14
  • 19
9
votes
2 answers

GitPython equivalent of "git remote show origin"?

I'm trying to update a Python script that checks the status of a handful of local repositories against remotes from using subprocess to using GitPython. What is the equivalent command in GitPython for git remote show origin, or what is the better…
wes
  • 1,577
  • 1
  • 14
  • 32
9
votes
3 answers

Using GitPython module to get remote HEAD branch

I'm trying to use GitPython to write some Python scripts which I can use it to simplify my daily tasks as I manage many branches. I'm also quite new for Python when it comes to writing complicated scripts. This is the API I used: GitPython API doc I…
samxiao
  • 2,587
  • 5
  • 38
  • 59
8
votes
2 answers

How to get file data from a specific git commit using gitpython

I am trying get a file from a specific commit using gitpython python-module. I'm able to get the file (with content) from the latest commit. However I want to get the file (with content) from a specific previous git commit. repo =…
Hari K
  • 251
  • 3
  • 8
8
votes
9 answers

git executable not found in python

I was trying to clone a git repo with access key, but when I am trying to run it, It throws an exception saying git executable not found. But i have installed git and the in_it.py shows correct path "C:\Program Files\Git\bin" Also I have installed…
Madhav Attili
  • 81
  • 1
  • 1
  • 2
8
votes
3 answers

Use GitPython to Checkout a new branch and push to remote

Given a repo from GitPython, how can I create a new local branch, add some files, and push it to remote using GitPython? To create a repo: from git import * curr_dir = os.path.dirname(os.path.realpath(__file__)) repo = Repo(curr_dir) For now, I'm…
etlsh
  • 701
  • 1
  • 8
  • 18
8
votes
2 answers

Get All Revisions for a specific file in gitpython

I am using gitpython library for performing git operations, retrieve git info from python code. I want to retrieve all revisions for a specific file. But couldn't find a specific reference for this on the docs. Can anybody give some clue on which…
Rana
  • 5,912
  • 12
  • 58
  • 91
8
votes
2 answers

Using GitPython, how do I do git submodule update --init

My code so far is working doing the following. I'd like to get rid of the subprocess.call() stuff import git from subprocess import call repo = git.Repo(repo_path) repo.remotes.origin.fetch(prune=True) repo.head.reset(commit='origin/master',…
Andrew
  • 1,027
  • 1
  • 11
  • 17
8
votes
3 answers

GitPython get tree and blob object by sha

I'm using GitPython with a bare repository and I'm trying to get specific git object by its SHA. If I used git directly, I would just do this git ls-tree sha_of_tree git show sha_of_blob Since I'm using GitPython and I want to get a specific tree,…
jernejl
  • 105
  • 3
  • 9
7
votes
4 answers

How to remove git repository, in python, on windows

As the title describes, I need to remove a git repository by using python. I've seen other questions about this very same topic, but none of the solutions seem to work for me. My work: I need to download a repository, using gitpython, followed by…
Kuratorn
  • 295
  • 1
  • 4
  • 8
7
votes
5 answers

How to download single file from a git repository using python

I want to download single file from my git repository using python. Currently I am using gitpython lib. Git clone is working fine with below code but I don't want to download entire directory. import os from git import Repo git_url =…
Ravi Ranjan
  • 399
  • 1
  • 5
  • 11
1 2
3
32 33