All Questions
Tagged with gitpython python-3.x
58 questions
0
votes
0
answers
97
views
GitPython unable to execute command in existing repository
I am trying to run a script with GitPython, but it seems to only fail when I run from inside the Jenkins automation environment. The error that it gives isn't very helpful (and I haven't been able to ...
1
vote
1
answer
159
views
Add safe directory with gitpython
How do I run this git command with gitpython(v2.1.*), please ?
git config --global --add safe.directory "some_dir"
Couldn't find in doc.
I tried this:
repo = git.Repo.init(some_dir)
config =...
0
votes
0
answers
109
views
Trouble pushing to Git remote using GitPython: "remote unpack failed" and "RPC failed; HTTP 500"
I'm encountering issues when trying to push changes to a Git remote repository using GitPython. I'm receiving two different errors intermittently, and I'm unsure how to resolve them.
Error 1
error: ...
0
votes
1
answer
195
views
How to call rev_list with GitPython
This program fails
import git
repo = git.repo.Repo('..')
res = repo.git.rev_list('--since="2024-01-01" master').split('\n')
with the following error
git.exc.GitCommandError: Cmd('git') ...
6
votes
2
answers
3k
views
How to get master/main branch from gitpython
How one can know about the master/main branch at git remote with git-python.
I am aware that we can iterate over the heads of the repository and then check the results. Something like
repo = git.Repo('...
5
votes
2
answers
7k
views
How to install gitpython with, Failed to initialize: Bad git executable
I am trying to install git-python on Windows. I tried to install it using the git command:
pip install gitpython
It installed just fine and it install in my local app data. The only problem was is ...
0
votes
1
answer
327
views
GitPython: get rename files as deleted and added
I need to get git diff files since specific commit using GitPython. As I understood I get renamed files using 'R' type . Is it possible to get the rename_from in the deleted lists and the rename_to in ...
0
votes
1
answer
637
views
Mocking GitPython Repo Calls
I've got a class with a function that adds unstaged changes in a git repo and commits them
def commit_local_changes(self, repo_path):
repo = Repo(repo_path)
changed_files = repo....
7
votes
5
answers
28k
views
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.
...
0
votes
0
answers
1k
views
module 'git' has no attribute 'Repo' - when running as non-root user.. works as root user
As above, I wrote a gitlab pre-receive hook that runs as a 'git' user on our gitlab server. When testing it, I get the above error. However when I SSH into the server and manually run the script as ...
1
vote
2
answers
2k
views
How to use python to check whether there are unstaged/uncommitted change or unpushed commit in a git repo
How to use python to check whether there are unstaged/uncommitted change or unpushed commit in a git repo?
I only know the command line
git status would tell
unstaged change
uncommitted stage
also ...
4
votes
2
answers
10k
views
How to get the latest commit hash on remote using gitpython?
Is there a way that I can get the most recent commit on a remote repository using gitpython?
I do not want to perform operations like a pull or merge on my local branch. I also do not want to depend ...
18
votes
1
answer
11k
views
Using gitpython, how can I checkout a certain Git commit ID?
Checking out a branch works well, but I also need to check out a certain commit ID in a given Git repository.
I mean the equivalent of
git clone --no-checkout my-repo-url my-target-path
cd my-target-...
0
votes
1
answer
242
views
How to execute --track, using GitPython(as a python script). "git checkout -B <branchname> --track origin/<TeamBranch>"
I can execute "git checkout -B --track origin/TeamBranch" through terminal. but I have the requirement to implement the above command through my script using Gitpython.
can someone help me ...
0
votes
0
answers
1k
views
How to get time of last commit date for Git repository files via Python?
I'm trying to get the latest commit date for each file in a specific folder in a repo.
My code:
import git
import os
dir_path = os.path.dirname(os.path.realpath(__file__))
repo = git.Repo(dir_path)
...