0

I have the problem that I want to update/overwrite my local folder with a Repository, but I cant find information about how I can do that with Python. When I am cloning it I have to have a empty folder which is not the case for me.

Thank in advanced!

  • Have you seen [Daniel Jonsson's comment](https://stackoverflow.com/questions/15315573/how-can-i-call-git-pull-from-within-python) about using the built in Git pull feature of the Git module? – Michael S. Jul 13 '22 at 14:08

2 Answers2

0

If you want to recreate a folder or update it can use with mkdir() function. Otherwise, if you want to delete it you can use shutil.rmtree() function to delete a folder with all content of in it. more ditailes here

Daniel Azemar
  • 478
  • 7
  • 19
0

If I understand your problem correctly, os module is all you need! The steps are below:

  1. To clone the repository:

     import os
     github_repository_url = 'https://github.com/<user_name>/<repository_name>.git'
     os.system(f'git clone {github_repository_url}')
    
  2. Move to the directory:

     os.system(f'cd <repository_name>')
    
  3. Take a pull i.e., update the repository:

     os.system('git pull')
    

Replace the placeholders <...> where necessary.

fuad021
  • 88
  • 6