- Repo name
- User name
- Filepath to track (the file)
- Default Commit Message
- Mainly , Oauth Token . you can get it from here
Navigate to https://github.com/settings/tokens . Then click on generateNewToken . You will be prompted by ,
Then click on repo Radio button for permission to access the repo .
Then you will get a token . Make sure you copy it some where . bcoz its the last time you are seeing it .
Hurray !! You got the Token .
- Open gitAutoPush.py file .
- Edit all the necessary details such as ,
self.filename = 'tes_file.txt' # Your file name
self.git_repo_name = 'gitAutomatePush' #Do not include .git extension
self.git_user_name = 'syedjafer' # username
self.git_oauth_token = '<Your Auth Token>' # Your Auth Token
self.git_commit_msg = 'Update the file' # Your Commit Message
-
This snippet will track the file for changes using the timestamp . If it encounters with a change in timestamp (Means there is a change in the content of the file and its ready to be pushed ) . It will add the file in the git and commir it with the default commit message .
-
Problem of providing the username and password (here we used oauth token) is been smashed with the inline specification in
os.system("git push https://%s:%s@github.com/%s/%s.git"%( self.git_user_name,self.git_oauth_token,self.git_user_name,self.git_repo_name))
There are two ways of running this program .
-
You can put it in the cronjob , (so that it will be triggered for every fiveminutes or your time specification )
-
Run the program infinite times. 😛