Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I commit and push to github from python shell?

I have three .py files saved in the python shell/IDLE. I would like to commit and push them to my GitHub account/repo. Is this possible? and if so how?

like image 610
Rosalind Cooper Avatar asked Oct 09 '15 14:10

Rosalind Cooper


People also ask

How do I push a project from Pycharm to GitHub?

To push changes from the current branch press Ctrl+Shift+K or choose Git | Push from the main menu. To push changes from any local branch that has a remote, select this branch in the Branches popup and choose Push from the list of actions.


1 Answers

To do it from macOS (Mac terminal) using the shell from python, you can do this:

#Import dependencies
from subprocess import call

#Commit Message
commit_message = "Adding sample files"

#Stage the file 
call('git add .', shell = True)

# Add your commit
call('git commit -m "'+ commit_message +'"', shell = True)

#Push the new or update files
call('git push origin master', shell = True)
like image 114
My Name Avatar answered Oct 15 '22 00:10

My Name