pythongitpythondulwich

Python: git remote add -f origin in Dulwich


i want execute

git remote add -f origin <repo>

with dulwich. however, i couldn't find something in this direction.

Knows somebody a solution or an alternative in gitpython?

Thanks for ideas.


Solution

  • In Dulwich master, you can use the dulwich.porcelain.remote_add method:

    from dulwich import porcelain
    porcelain.remote_add('origin', 'http://github.com/git/git')
    

    In older versions (that don't have porcelain.remote_add) you can use something like:

    from dulwich.repo import Repo
    c = Repo('.').get_config()
    c.set(('remote "origin"', ), "url", "http://github.com/git/git") 
    c.write_to_path()