Skip to content

Instantly share code, notes, and snippets.

@nibirrayy
Created January 25, 2021 17:55
Show Gist options
  • Save nibirrayy/20003f6ab818fef8ff5c834968890968 to your computer and use it in GitHub Desktop.
Save nibirrayy/20003f6ab818fef8ff5c834968890968 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
##############################################################
# Maintainer: Nibir Ray #
# Email: [email protected] #
#
# This is simple python scrpit that eases the git workflow #
# this is inspired by pacman
# -C for commits
# -Ca to commit all
# -B for branches
# -P to push
# -U to pull/update
##############################################################
import os
import json # imporing json so that we can save all env varibles in a json file
import sys
cur_dir = os.getcwd() # saving the current working directly in a variable
# Checking if it is a git repository if it is not then initalizing it
if (os.path.exists(f"{cur_dir}/.git")):
print ("No need to initialize")
else:
print("Need to instalize git repository")
os.system('git init')
def commit_all_changes(commit_message):
os.system('git add .')
print(f"commiting all changes with message: {commit_message}")
os.system(f'git commit -m \"{commit_message}\"')
def commit_changes(*files,commit_message):
for file in files:
os.system(f"git add {file}")
os.system(f'git commit -m \"{commit_message}\"')
def commit_all_and_push(commit_message):
commit_all_changes(commit_message)
os.system("git push")
def push_changes():
os.system("git push")
def pull_changes():
os.system("git pull")
if (sys.argv[1] == "-C"):
print ("Commiting specified changes")
commit_changes(sys.argv[2],sys.argv[3])
elif (sys.argv[1] == "-Ca"):
print ("Commiting all changes")
commit_all_changes(sys.argv[2])
elif (sys.argv[1] == "-Cap"):
print ("commiting all changes and pushing to remote repository")
commit_all_and_push()
elif (sys.argv[1] == "-B"):
print ("Branching")
elif (sys.argv[1] == "-P"):
print ("Pushing changes")
push_changes()
elif (sys.argv[1] == "-U"):
print ("Pulling latest changes from remote repo")
pull_changes()
else:
print("Wrong Input!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment