Home > Mobile >  Download Repository to local folder and overwrite existing files by using Python
Download Repository to local folder and overwrite existing files by using Python

Time:07-14

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!

CodePudding user response:

if you want to recreate a folder or update it can use with mkdir() function. but 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

CodePudding user response:

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.

  • Related