{"id":335,"date":"2023-08-07T10:03:04","date_gmt":"2023-08-07T16:03:04","guid":{"rendered":"https:\/\/kop.lat\/blog\/?p=335"},"modified":"2023-08-07T10:05:25","modified_gmt":"2023-08-07T16:05:25","slug":"335-2","status":"publish","type":"post","link":"https:\/\/kop.lat\/blog\/335-2\/","title":{"rendered":"Script to check the git status of multiple repos in the same directory"},"content":{"rendered":"\n<p>Recursively, enters each folder and executes the &#8220;git status&#8221; command in each folder. <\/p>\n\n\n\n<p>It can also be modified to be &#8220;git pull&#8221; or something else.<\/p>\n\n\n\n<p>The deep level is 1, meaning, only the folders in the actual folder and not folders inside of. <\/p>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\" snippet-height=\"\" style=\"background-color:#abb8c3\"><div class=\"control-language\"><div class=\"dm-buttons\"><div class=\"dm-buttons-left\"><div class=\"dm-button-snippet red-button\"><\/div><div class=\"dm-button-snippet orange-button\"><\/div><div class=\"dm-button-snippet green-button\"><\/div><\/div><div class=\"dm-buttons-right\"><a id=\"dm-copy-raw-code\"><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\" style=\"display:none\">Copied<\/span><span class=\"dm-error-message\" style=\"display:none\">Use a different Browser<\/span><\/a><\/div><\/div><pre class=\" line-numbers\"><code id=\"dm-code-raw\" class=\" no-wrap language-python\"># Pull all repositories in folders recursively with colors\n# this script uses subprocess and not the regular os.system method\n\nimport os\nimport subprocess\nfrom colorama import init, Fore\n\n\ndef git_pull_in_folders(path_folder):\n\n    init(autoreset=True)\n\n    for folder_name in os.listdir( path_folder ):\n\n        folder_path = os.path.join(path_folder, folder_name)\n\n        if os.path.isdir( folder_path ):\n            print(Fore.YELLOW + f\"git status [CHECKING] in folder: [{folder_name}]\")\n            try:\n                subprocess.run(['git', 'status'], cwd=folder_path, check=True)\n                print(Fore.GREEN + f\"git status [COMPLETE]- folder: [{folder_name}] ...\")\n            except subprocess.CalledProcessError:\n                print(Fore.RED + f\"git status [FAILED] failed - folder: [{folder_name}] ...\")\n\n\nif __name__ == \"__main__\":\n\n    folder_path = '.\/'\n    git_pull_in_folders(folder_path)\n\n<\/code><\/pre><\/div><\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recursively, enters each folder and executes the &#8220;git status&#8221; command in each folder. It can also be modified to be &#8220;git pull&#8221; or something else. The deep level is 1, meaning, only the folders in the actual folder and not folders inside of.<\/p>\n","protected":false},"author":2,"featured_media":230,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[36,41,20,32,9,13,14,31,45,7,8,40],"tags":[],"_links":{"self":[{"href":"https:\/\/kop.lat\/blog\/wp-json\/wp\/v2\/posts\/335"}],"collection":[{"href":"https:\/\/kop.lat\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kop.lat\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kop.lat\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/kop.lat\/blog\/wp-json\/wp\/v2\/comments?post=335"}],"version-history":[{"count":2,"href":"https:\/\/kop.lat\/blog\/wp-json\/wp\/v2\/posts\/335\/revisions"}],"predecessor-version":[{"id":338,"href":"https:\/\/kop.lat\/blog\/wp-json\/wp\/v2\/posts\/335\/revisions\/338"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kop.lat\/blog\/wp-json\/wp\/v2\/media\/230"}],"wp:attachment":[{"href":"https:\/\/kop.lat\/blog\/wp-json\/wp\/v2\/media?parent=335"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kop.lat\/blog\/wp-json\/wp\/v2\/categories?post=335"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kop.lat\/blog\/wp-json\/wp\/v2\/tags?post=335"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}