Questions tagged [pygit2]

Pygit2 is a set of Python bindings to the libgit2 shared library.

Filter by
Sorted by
Tagged with
32 votes
5 answers
43k views

How to get the current checked out Git branch name through pygit2?

This question should be related to: How to get the current branch name in Git? Get git current branch/tag name How to get the name of the current git branch into a variable in a shell script? How to ...
Drake Guan's user avatar
  • 14.8k
15 votes
2 answers
4k views

Create a commit using pygit2

I would like to make a commit on a branch (master for example). I am making a repository clone using pygit2 (pygit2.clone_repository) Then I change an existing file in the repository. Afterwards I ...
user1479699's user avatar
13 votes
4 answers
3k views

Git Commit Parents' Order

Is there some convention for the order of a commit's parents? Because one of the commit's parents should be to be to previous commit on the current branch that is being merged into and the rest are ...
Emil Davtyan's user avatar
  • 13.9k
12 votes
1 answer
10k views

Create, Clone, and Push to GitHub repo using PyGitHub and PyGit2

How can I create a new GitHub repository, clone it, change files, and then push it back to github using python and the pyGitHub and pyGit2 libraries? The documentation for both libraries is very ...
Bar Smith's user avatar
  • 837
6 votes
2 answers
4k views

How do you checkout a branch with pygit2?

I want to use pygit2 to checkout a branch-name. For example, if I have two branches: master and new and HEAD is at master, I would expect to be able to do: import pygit2 repository = pygit2....
nebffa's user avatar
  • 1,529
5 votes
1 answer
807 views

Untracked dirs on commit with pygit2

I'm working on a non-bare repository with pygit2 index = repo.index index.read() # write in test/test.txt index.add('test/test.txt') treeid = index.write_tree() repo.create_commit( 'HEAD', ...
linkdd's user avatar
  • 1,025
5 votes
1 answer
4k views

Implementing Pull with Pygit2

I am trying to implement some 'porcelain' commands using pygit2. It seems that I have run into a bit of road block while implementing pull. Specifically the easiest pull case, a fast forward. Setup: ...
Michael Boselowitz's user avatar
5 votes
0 answers
410 views

How to rebase with pygit2?

I'm stuck trying to implement a git rebase with pygit2. Assuming this repo history, how to rebase topic on master using pygit2 ? (ie, the equivalent of git rebase master topic): A---B---C ...
skadge's user avatar
  • 131
4 votes
3 answers
1k views

Difference between "(no branch)" and "(detached at abc1234)"

Normally when you run something like this inside of a git repository: git checkout abc1234 You end up in a detached HEAD state. If you run git branch, the output will look something like this: * (...
Matthew G's user avatar
  • 1,090
4 votes
2 answers
2k views

Replicating "git checkout <commit> with PyGit2

I am trying to replicate the behaviour of the command "git checkout (commit)" where (commit) is the reference to as specific commit and not a branch name. When using this command, the 'HEAD' of the ...
Maeln's user avatar
  • 370
4 votes
1 answer
546 views

Pygit2: Why does merge leave branch in an unclean state?

I'm currently running Pygit 0.24.1 (along with libgit 0.24.1), working on a repository where I have two branches (say prod and dev). Every change is first commited to the dev branch and pushed to the ...
nKn's user avatar
  • 13.7k
3 votes
3 answers
2k views

How to know if a git repository is clean with Python3 (pygit2)?

I'm trying to determine if a or git commit is needed in a git repository. I come up with this code that works fine for me : def is_dirty(repo): import pygit2 status = repo.status() for ...
Laurent Claessens's user avatar
3 votes
2 answers
2k views

Extract commits related to code changes from commit tree

Right now I am able to traverse through the commit tree for a github repository using pygit2 library. I am getting all the commits for each file change in the repository. This means that I am getting ...
Zack's user avatar
  • 2,138
3 votes
4 answers
3k views

Installing pygit2/libgit2 in Python virtualenv on a Mac

I think I'm about to lose my mind. I'm trying to simply install pygit2 in my python virtualenv on my macbook air so I can get to work. However this is not budging and I have been trying to set it up ...
Emil Davtyan's user avatar
  • 13.9k
3 votes
1 answer
3k views

How to set the credentials in pygit2.clone_repository?

When I clone a repo from github by pygit2, it returns: 'OSError: Failed to send request: A security error occurred' The code is simple, import pygit2 username = 'MyGitHubUsername' password = '...
user3196254's user avatar
3 votes
1 answer
3k views

pygit2 clone_repository authentication required but no callback set

I'm trying to clone a repository from stash using an ssh link. I get an error saying authentication is required, This should not require a username and password. How do I fix this error? from ...
user3916885's user avatar
2 votes
2 answers
5k views

how to use git pull with GitPython?

I am trying to pull filesfrom git using python but it's not working. Below is the code I was using: import git git.cmd.Git().pull('https://github.com/User/repo','master') it asks for authentication ...
ZZ3111's user avatar
  • 67
2 votes
2 answers
3k views

Installing libgit2 and pygit2 on Debian Docker

I have been trying to install pygit2 and libgit2 using a Debian:Jessie docker file. I was able to compile the package with almost the same packages with ubuntu, but not with debian. Below is the ...
Mo J. Mughrabi's user avatar
2 votes
1 answer
723 views

How to print the contents of a pygit object in python

I am trying to print the "diff" object as shown below. I am expecting an output similar to git show , but I am not getting the same. How do I achieve this? Thanks. import pygit2 repo=pygit2....
Zack's user avatar
  • 2,138
2 votes
1 answer
2k views

pulling and integrating remote changes with pygit2

I do have the following problem. I'm writing a script which searches a folder for repositories, looks up the remotes on the net and pulls all new data into the repository, notifying me about new ...
Toni Barth's user avatar
2 votes
1 answer
444 views

Unusual behavior of jinja2 template_filter decorator in flask application

I have a filters.py file in my flask application and its content is: # -*- coding: utf-8 -*- from __future__ import absolute_import, unicode_literals, print_function import arrow from fresque import ...
Rahul's user avatar
  • 2,096
2 votes
1 answer
710 views

How to make an initial commit using pygit2?

Using the pygit2 package how do you create an initial commit on a new repository? I keep getting an error message that "refs/heads/master" isn't found.
Connor Fuhrman's user avatar
2 votes
1 answer
932 views

Pygit2: Need help on how to walk on all commits in all repo's branches

I'd need to walk on entire repo's branches commits. I have tried this but with no success. : for branch_name in list(repo.branches.remote): try: branch = repo.lookup_branch(branch_name) ...
user2326167's user avatar
2 votes
1 answer
582 views

How to get lines changed for each file in a diff in pygit2

Using, pygit2, I can get the total number of files changed, total insertions, total deletions, and the relative path of the files. See below code. However, I can't find a way to get the stats on lines ...
Nasif Imtiaz Ohi's user avatar
2 votes
1 answer
545 views

How to import pygit2 library into AWS lambda python3.8 runtime

I am facing an issue with AWS lambda function. I am unable to import pygit2 library into my function. I tried it on 4 different runtime environments and each gives a different error, which makes me ...
Lukas's user avatar
  • 33
2 votes
1 answer
92 views

pip requirement based on available OS library version

I am developing a python package based on pygit2. pygit2 depends on libgit2. Ubuntu 18.04 has version libgit2-2.6 Ubuntu 18.10 has version libgit2-2.7 In my requirements.txt/Pipfile, if I have "...
balki's user avatar
  • 26.9k
2 votes
0 answers
1k views

Install pygit2 with pip in the same version as libgit2

I have a project that depends on the pygit2 library. The pygit2 library in turn depends on the locally installed libgit2 and both have to match the minor-version: https://www.pygit2.org/install.html#...
white_gecko's user avatar
  • 4,918
2 votes
0 answers
142 views

pygit2 appears to return the wrong flags for repo.status()

I'm running repo.status().items() in a pre-commit hook using the -a flag (git commit -a -m "Test"), and I get a result that looks like this: [('config/git_hooks/pre-commit', 256), ('bin/run_flake8', ...
Chris B.'s user avatar
  • 87.3k
2 votes
0 answers
200 views

Sublime Text 2/3 - How to embed python module (pygit2) with cross-platform (debian & windows) support

I want to use pygit2's libgit2 bindings inside a Sublime Text plugin. Q: Is it possible to embed a functional version of pygit2 and libgit2 that ST can import for both Windows 32bit/64bit and Debian ...
ThorSummoner's user avatar
  • 17.2k
2 votes
0 answers
395 views

Pygit2: How to unstage a file?

In pygit2, if I stage the adding or removing of a file, how can I unstage them like I'd do with git reset? I need to use pygit2 to accomplish the following git actions: git reset HEAD git checkout . ...
pistacchio's user avatar
  • 57.8k
1 vote
1 answer
2k views

List all commits since last release when the tag points to a commit on other branch

I need to list all the commits made to the master branch since my last release. I have to implement this functionality using pygit2. But the situation is a bit different here. The release is made on ...
darxtrix's user avatar
  • 2,040
1 vote
1 answer
1k views

How to make a git merge by pygit2

I try to merge branch into master: repo = pygit2.Repository("/path/to/repo/") branch = repo.lookup_branch("upstream/branch", pygit2.GIT_BRANCH_REMOTE) oid = branch.target merge_result = repo.merge(...
Alexander Bayandin's user avatar
1 vote
1 answer
2k views

How do I set ssh credentials for libgit2/libssh2?

I am attempting to push references from within pygit2/libgit2: push_refspec = git_repo.lookup_reference('HEAD').resolve().name logger.info("Pushing " + push_refspec) git_remote.push(...
David Greene's user avatar
1 vote
1 answer
126 views

How get list submodules from git bare repo without create working tree?

How get list submodules in git bare repo without create working tree? (with low level library libgit2 or git console)?
Иван Куликов's user avatar
1 vote
1 answer
632 views

How can I perform a rebase with pygit2?

This question touches on how to perform a merge with pygit2, but, to the best of my understanding, that will result in a new commit. Is there a way to perform a rebase, which will not result in a new ...
Piotrek's user avatar
  • 102
1 vote
1 answer
526 views

Pygit2 - Merging a branch with no fast forward

I am essentially trying to do a "git merge --no-ff branch" to merge my branch back in. Looking at the Pygit2 documentation, I am not entierly sure what the correct way to do this is. The direct ...
Stephen Lu's user avatar
1 vote
1 answer
410 views

HEAD detatched from origin/master when merging with pygit2

I am using pygit2 to merge some branches of a project, however whenever I merge them I end up with: def avoid_walls(directions, board, snake): <<<<<<< HEAD return directions =====...
Pottsiex5's user avatar
  • 487
1 vote
1 answer
180 views

Getting full indexes of a patch using libgit2 / git2go

git2go's git.Patch or libgit2's git_patch returns a String value of the following format: "diff": "diff --git a/test b/test index 9daeafb..dced80a 100644 --- a/test +++ ...
Jessica Yuen's user avatar
1 vote
1 answer
308 views

Git porcelain commands via pygit2?

Pygit2 is a set of Python bindings to the libgit2 shared library, which implements the Git core methods. Unfortunately, it only seems to provide an API towards plumbing commands. Is there any python ...
Roberto Aloi's user avatar
  • 30.8k
1 vote
1 answer
3k views

Steps for pulling from remote using pygit2

While using the pygit2 library a simple repo.fetch() fetches all the diffs. The answer here describes the steps viz 1. Remote.fetch() 2. Repository.create_reference() or Reference.target= 3. ...
avck's user avatar
  • 3,605
1 vote
1 answer
2k views

How to install libgit2/pygit2 into virtualenv? (Ubuntu)

I have tried dulwich, and GitPython - neither of which seem mature. Now I am trying to install libgit2/pygit2. I have successfully installed them into the host packages environment, but now I need to ...
RSAdmin's user avatar
  • 439
1 vote
1 answer
466 views

pygit2: How to "git remote set-branches origin remote_branch_name"

Title says it all. I am using pygit2 and trying to figure out how to achieve following that I can do using git cli: git remote set-branches origin remote_branch_name
hasanatkazmi's user avatar
  • 8,239
1 vote
1 answer
2k views

Get all the file Contents of a repo at Specific Commit using PyGitHub

I want to get the file contents of all the files in the repo [changed and unchanged] using the Python [PyGitHub API]. But not sure how to achieve it. Simply, to browse the repo at that specific commit ...
lucifer7's user avatar
1 vote
2 answers
1k views

how to interpret pygit2 status info

I am using pygit2 to access that status of the repo status = repo.status() for filepath,flags in status.items(): print ("path %s flags %d", filepath, flags) I dont seem to be able to find any ...
GrahamL's user avatar
  • 243
1 vote
1 answer
821 views

Errors installing pygit2 on CentOs

I am trying to install pygit2 on Centos and am getting the following error I would be grateful if anyone could suggest what may be wrong thanks You are using pip version 7.1.0, however version 9.0.1 ...
GrahamL's user avatar
  • 243
1 vote
1 answer
396 views

Does Repository.walk traverse all commits

In pygit2, Repository.walk can be used to traverse commits starting from a commit. However the docs do not explictly say whether all commits in the repository will be traversed, including dangling ...
simonzack's user avatar
  • 20.2k
1 vote
1 answer
4k views

Unable to ssh push in pygit2

I am trying to push using ssh to a github repo using pygit2. Here is the error I keep getting. Can you point out the error? >>> sshcred = repo_.pygit2.credentials.Keypair('avckp','id_rsa.pub'...
avck's user avatar
  • 3,605
1 vote
1 answer
332 views

Staging an individual hunk using PyGit2

I'm trying to implement git add -p in pygit2, so I can make an alternative frontend to it. So I need to be able to stage individual hunks, first and foremost. I'm able to find the hunks by using ...
zdsmith's user avatar
  • 13
1 vote
0 answers
130 views

How to get branch name if checked out to origin/branch with pygit2?

If the cloned repo is in detached HEAD state and points to origin/<branch>, how do I get the original branch name? git status shows HEAD detached at origin/<branch>, so it should be ...
Anton K's user avatar
  • 71
1 vote
1 answer
690 views

How to get name current bramch name in a git repository using python

This is the script to get the current branch name in git using ssh key URL = raw_input('Enter the ssh git URL: ') print URL from pygit2 import Repository repo = Repository(URL) # option 1 head = ...
kishore's user avatar
  • 41