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.

439 questions
37
votes
3 answers

git log --follow, the gitpython way

I am trying to access the commit history of a single file as in: git log --follow -- I have to use gitpython, so what I am doing now is: import git g = git.Git('repo_dir') hexshas =…
Alberto Bacchelli
  • 939
  • 1
  • 8
  • 9
23
votes
1 answer

List file that have changed since last commit with GitPython

I need to have the Python script read in the files that have changed since the last Git commit. Using GitPython, how would I get the same output as running from cli: $ git diff --name-only HEAD~1 HEAD I can do something like the following,…
Cmag
  • 12,570
  • 23
  • 75
  • 129
23
votes
4 answers

How can I pull a remote repository with GitPython?

I am trying to find the way to pull a git repository using gitPython. So far this is what I have taken from the official docs here. test_remote = repo.create_remote('test', 'git@server:repo.git') repo.delete_remote(test_remote) # create and delete…
Uuid
  • 2,146
  • 5
  • 25
  • 36
21
votes
1 answer

How to check out a branch with GitPython

I have cloned a repository with GitPython, now I would like to checkout a branch and update the local repository's working tree with the contents of that branch. Ideally, I'd also be able to check if the branch exists before doing this. This is what…
Alex Spurling
  • 47,884
  • 23
  • 63
  • 71
21
votes
6 answers

GitPython and SSH Keys?

How can I use GitPython along with specific SSH Keys? The documentation isn't very thorough on that subject. The only thing I've tried so far is Repo(path).
andreihondrari
  • 5,441
  • 5
  • 25
  • 54
20
votes
2 answers

Python os.getlogin problem

If i create a file like: import os print os.getlogin() and run it with cron, I get an exception print os.getlogin() OSError: [Errno 22] Invalid argument If I run it manually in shell -- it works. Problem is, GitPython 0.3.1 in commit() uses this…
gistart
  • 295
  • 1
  • 4
  • 6
19
votes
1 answer

Get changed files using gitpython

I want to get a list of changed files of the current git-repo. The files, that are normally listed under Changes not staged for commit: when calling git status. So far I have managed to connected to the repository, pulled it and show all untracked…
Jakube
  • 2,618
  • 2
  • 18
  • 39
19
votes
6 answers

get short sha of commit with gitpython

The long SHA can be gotten like below: repo = git.Repo(search_parent_directories=True) sha = repo.head.object.hexsha Or, in git 3.1.7: sha = repo.head.commit.hexsha How about short one? (short SHA is decided by the scale of the repo, so it should…
Kentaro Wada
  • 405
  • 1
  • 4
  • 12
18
votes
3 answers

gitpython git authentication using user and password

I'm using GitPython but did not find a way to push to repo using username and password. Can anybody send me a working example or give me some pointer about how to do it? What I need to do is: add a file to the repository, push it using the username…
ozw1z5rd
  • 2,517
  • 2
  • 22
  • 39
18
votes
4 answers

GitPython tags sorted

I am trying to get the latest tag in the repo using GitPython lib. Usually I was doing it this way: repo = Repo(project_root) last_tag = str(repo.tags[-1]) But once version 1.10 was released, I am always getting 1.9 ;( I know it's related to output…
Ilia Shakitko
  • 1,348
  • 2
  • 17
  • 25
18
votes
6 answers

gitpython and git diff

I am looking to get only the diff of a file changed from a git repo. Right now, I am using gitpython to actually get the commit objects and the files of git changes, but I want to do a dependency analysis on only the parts of the file changed. Is…
user1816561
  • 219
  • 2
  • 3
  • 4
16
votes
6 answers

Checkout or list remote branches in GitPython

I don't see an option to checkout or list remote/local branches in this module: https://gitpython.readthedocs.io/en/stable/
Mike
  • 6,385
  • 8
  • 51
  • 76
14
votes
1 answer

How to get staged files using GitPython?

I'm counting staged files in git using GitPython. For modified files, I can use repo = git.Repo() modified_files = len(repo.index.diff(None)) But for staged files I can't find the solution. I know git status --porcelain but I'm looking for other…
Kentaro Wada
  • 405
  • 1
  • 4
  • 12
14
votes
3 answers

How to do a git reset --hard using gitPython?

Well the title is self explanatory. What will be the python code equivalent to running git reset --hard (on terminal) using GitPython module?
Anuvrat Parashar
  • 2,602
  • 1
  • 26
  • 49
13
votes
5 answers

Git push via GitPython

I have this code in Python (using "import git"): repo = git.Repo("my_repository") repo.git.add("bla.txt") repo.git.commit("my commit description") Now I want to push this commit. I've tried a lot with no success. The Python command should be…
amigo
  • 131
  • 1
  • 1
  • 3
1
2 3
29 30