Created
September 11, 2024 11:10
-
-
Save frankkwabenaaboagye/88592513fff1da509514c1feea349e1c to your computer and use it in GitHub Desktop.
Script that automates common Git commands. Pass the commit message as an argument when running the script
This file contains hidden or 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 subprocess | |
| import sys | |
| def run_command(command): | |
| result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
| if result.returncode == 0: | |
| print(result.stdout.decode('utf-8')) | |
| else: | |
| print(f"Error: {result.stderr.decode('utf-8')}") | |
| if __name__ == "__main__": | |
| if len(sys.argv) != 2: | |
| print("Usage: python git_script.py <commit_message>") | |
| sys.exit(1) | |
| commit_message = sys.argv[1] | |
| # Git add | |
| print("Adding all changes...") | |
| run_command("git add .") | |
| # Git commit | |
| print(f"Committing with message: {commit_message}") | |
| run_command(f'git commit -m "{commit_message}"') | |
| # Git status | |
| print("Checking status...") | |
| run_command("git status") | |
| # Git push | |
| print("Pushing to the repository...") | |
| run_command("git push") | |
| print("Done.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment