0

I have an existing README.md file in a github repository. How can I update the README.md file through a python script using github API? I guess the API states that we can get contents for a file. I want to know how do I add markdown text to the content, overwrite the README.md file and add it to the repository as a commit from within the python script using the API.

1 Answer 1

1

Use the PyGitHub module, which is a python wrapper for the GitHub api.

from github import Github

# Authenticate yourself 
g = Github("yourusername", "yourauthtoken")

# Find your repository and path of README.md
repo=g.get_user().get_repo("your repo")
file = repo.get_contents("README.md")

# The new contents of your README.md
content = "your updated README file contents"

# Update README.md
repo.update_file("README.md", "commit message", content, file.sha)
    
Sign up to request clarification or add additional context in comments.

1 Comment

Won't this replace the existing data with new data is there a way to append the new data and not impact the existing data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.