Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch git backend to pygit2 (uses libgit2) #329

Open
mahaloz opened this issue Aug 14, 2023 · 1 comment
Open

Switch git backend to pygit2 (uses libgit2) #329

mahaloz opened this issue Aug 14, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@mahaloz
Copy link
Member

mahaloz commented Aug 14, 2023

Description

The tile says it all.

Alternatives

No response

Additional context

No response

@mahaloz mahaloz added the enhancement New feature or request label Aug 14, 2023
@mahaloz
Copy link
Member Author

mahaloz commented Aug 21, 2023

Closing this issue should also close #328. Here is the PoC code:

import pygit2

# Path to your Git repository
repo_path = './path/to/repo'
repo = pygit2.Repository(repo_path)

# Fetch updates from the remote
remote_name = 'origin'
remote = repo.remotes[remote_name]
remote.fetch()

# Iterate through the local branches and reset them to the corresponding remote tracking branch
for branch in repo.branches.local:
    remote_branch_name = f'{remote_name}/{branch}'
    remote_branch = repo.branches[remote_branch_name]
    local_branch = repo.branches[branch]
    
    # Reset the local branch to the corresponding remote tracking branch
    repo.branches.update(local_branch.name, remote_branch.target)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant