1

I am working with shallow-clone and shallow fetch with GIT repo, There is Git-Python being used in the code

In Git-python, what would be equivalent command for the following git cmd command git remote set-branches origin --add master8

I read their docs, but couldn't make it work. Any help is appreciated.

Relevant code

repo = git.Repo('Demo1')
repo.remotes.origin.fetch('+refs/heads/master2:refs/remotes/origin/master2', depth=1)
'git remote set-branches origin --add  master2' # need to run this
# repo.git.remote('set-branches', 'origin', '--add', 'master2')
repo.git.checkout('master2')
repo.git.reset('--hard', f'origin/master2')
repo.git.clean('-dfx')
repo.remotes.origin.pull(depth=1)

1 Answer 1

0

This is not exactly an answer to the question, but here is a code fragment that retrieves all remote branches after a shallow clone. Changing the .git.remote to repo.git.remote('set-branches','origin','--add','master2') should also work and would be a more direct answer to this question.

import git
repo = git.Repo('/tmp/g2')
repo.git.remote('set-branches','origin','*')
repo.git.fetch()
branchlist = [i.strip() for i in repo.git.branch('-r').split('\n') if '->' not in i]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.