Mwaura
This article is meant for Linux users. (Sorry to you Windows and Mac folks out there)
Below is a glimpse of what to expect after finishing this tutorial.
import os
The OS module in python provides functions for interacting with the operating system. OS, comes under Python’s standard utility modules.
Space, " " is used as the separator. (It will separate all the strings in the argument vector.)
If we used a '###', here is how our message would look like.
$push initial commit
pushed with the message: initial###commit
We iterate over all the arguments from 1, (not 0 because the first argument is always the name of the program) and join them to form the message string.
os.system() method execute the command (a string) in a sub-shell.
os.system('git commit -m "{}"'.format(commit_message))
os.system("git push -u origin master")
Here, it's set up to track the master branch. You can change it to main depending on how you have configured your GitHub.
It would looks like this:
os.system("git push -u origin main")
print("\n\nPushed with message: {}".format(commit_message))
Feel free to get creative with the output.
Give yourself permission to execute the script by running the following command in your terminal.
$ chmod u+x push.py
chmod is used to control who can access files, search directories, and run scripts
We give the user execute permissions on the file push.py (I read u+x as add execute permission to user).
/usr/local/bin/push
cp push.py /usr/local/bin/push
$mv /usr/local/bin/push.py /usr/local/bin/push
This renames the file push.py to push
Incase of any errors while running the command, try prefixing the command withsudo
so as to execute it as admin. ie.sudo mv file1 file2
That's it. Happy pushing. Feel free to post any concerns on the comment section.
I'll be exploring how we can make the file accessible from anywhere using aliases in the next article.