Few days ago we talk about
1- Initiate git object in python by providing path:
2- If you want to
3- Let's say you want to set username and email for git author:
4- Now to add a specific file to staged:
5- Commit the staged file with a message:
6- The final step is to push to a remote repo:
#python #git #gitPython #pull #push #author
gitPython
to work with git inside of python. The code below is a sample that would do all routine tasks like pulling and pushing or commit.1- Initiate git object in python by providing path:
from git import Repo
repo = Repo(repo_path)
2- If you want to
pull
results from git repo:repo.git.pull('origin', 'refs/heads/dev')
3- Let's say you want to set username and email for git author:
config = repo.config_writer()
config.set_value("user", "email", author_email)
config.set_value("user", "name", author_name)
4- Now to add a specific file to staged:
index = repo.index
index.add([file_path])
5- Commit the staged file with a message:
index.commit(commit_message)
6- The final step is to push to a remote repo:
repo.git.push('origin', 'refs/heads/dev')
#python #git #gitPython #pull #push #author
If you forget to pull your projects from git in a regular interval and many users working on the same projects, then there is a solution for you!
Create a bash script file as follow and make it executable by
Now as a final step, put it in your crontab:
#linux #git #pull #cronjob #crontab #cron #bash
Create a bash script file as follow and make it executable by
chmod +x puller.sh
:puller.sh
file content:#!/bin/bash
echo 'Iterating over folders...'
for dir in *
do
test -d "$dir" && {
cd ${dir}
echo "git pull $dir"
git pull
cd ".."
} || {
echo "------> $dir is not a directory <-------"
}
done
NOTE:
this file should reside in your folder's project root. In my case it is in /Your/Projects/Folder
.Now as a final step, put it in your crontab:
10 * * * * bash -c "cd /Your/Projects/Folder; bash puller.sh >> /var/log/git_pull_output.log"
#linux #git #pull #cronjob #crontab #cron #bash