Fetch GitHub Commit Date (JS/TS)
How to fetch the date of a commit from the GitHub API
1 minute read
For an entire repository:
const response = await fetch(
'https://api.github.com/repos/[user]/[repo]/commits'
)
const commits = await response.json()
const latestCommit = commits[0]
const latestCommitDate = latestCommit.commit.author.date
For a specific file within a repository:
const response = await fetch(
'https://api.github.com/repos/[user]/[repo]/commits?path=[pathToFile]'
)
const commits = await response.json()
const latestCommit = commits[0]
const latestCommitDate = latestCommit.commit.author.date
Last Updated: