")The function will take in a file path to a text file (as a string) and write a new line in it with the text ‘new line’ (how original).
Write a function that will execute git add, commit, and push commands in the repository we previously set updef git_activities(repo): if len(repo.
commit('-m', 'initial commit') repo.
push('origin', 'HEAD:refs/for/master') The function accepts a Repo object (like the one we already declared) and first checks to see if there are any untracked files.
If there are, it will stage (add) all changes/additions, subsequently it will commit with a message, and finally it will push to the master.
Now we simply invoke the functions we wrote at the bottom of the filealter_file(file)git_activities(repo)We can save and exit our python script.
Now let’s open a new terminal window and once again type crontab -e15.
Press i to editWe would like to add a command that will run this python script we just wrote, sounds easy enough right?Well not so fast!Our python script has extra dependancies and we have to run this command through the virtual environment we set up.
To do this we will use this chained command:SHELL=/bin/bash* * * * * cd development/cronGit/venv && source bin/activate && cd .
&& python index.
py* * * * * five stars separated by spaces indicate that will run this every minute, every hour, every day, every month, at any day of the week…Then we have a chained command that is separated with &&First tread into the virtual environment location: cd development/cronGit/venvActivate the venv: source bin/activateTread one back out of the venv location back into where we saved our index.
py file: cd .
Lastly run our pythin script : python index.
pyAfter pasting the command into the crontab; it should look like this:You may now press esc and then follow it up with typing :wq to exitOK you’re all set up! You now look like a super active git user, who commits and pushes every minute of the day.
You also learnt about crontab recurring commands, and maybe a thing or two about the GitPython module.
link to git repo here.