OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How do I use a GitHub access token with GitPython?

  • Thread starter Thread starter polk54
  • Start date Start date
P

polk54

Guest
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:

Code:
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()
<p>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.</p>

<p>Here is my code so far:</p>

<pre><code>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()
</code></pre>
Continue reading...
 
Top