I am trying to write a python script that when run, will push files to one of my GitHub repositories. I'm using the package GitPython. I want to use an access token to log in into my GitHub account (instead of entering my username and password) because I have two-factor authentication. I've created the token, but I can't figure out how to add it to my GitPython code.
Here is my code so far:
def push(repo_dir):
import os
from git import Repo
# set working directory
os.chdir("XXX")
#repo_dir = 'Pantone'
repo = Repo(repo_dir)
file_list = [
"index.html",
"Data/colors.csv"
]
commit_message = 'Adding new color'
repo.index.add(file_list)
repo.index.commit(commit_message)
origin = repo.remote('origin')
origin.push()
HTTPS_REMOTE_URL = 'https://<access_token>:[email protected]/username/your-project'
in your git config file. – Motmot