Last active
August 10, 2024 13:16
-
-
Save Eveeifyeve/9a6875751432b39ec734803cd9ae90b5 to your computer and use it in GitHub Desktop.
backup-reposPyScrpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import subprocess | |
def is_git_repo(path): | |
return os.path.exists(os.path.join(path, '.git')) | |
def backup_and_push(path): | |
if is_git_repo(path): | |
print(f"Backing up {path}...") | |
subprocess.run(['git', '-C', path, 'add', '.']) | |
subprocess.run(['git', '-C', path, 'commit', '-m', '"feat: git backup"']) | |
subprocess.run(['git', '-C', path, 'push']) | |
else: | |
print(f"{path} is not a Git repository.") | |
current_dir = os.getcwd() | |
for root, dirs, _ in os.walk(current_dir): | |
for d in dirs: | |
backup_and_push(os.path.join(root, d)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment