Commits

Learn and practice the functionalities of commits in GitHub API.

Overview

Commits are a version history of our repository. Snapshots of our repository are taken from time to time, which show how the changes were made. Whenever we make any logical changes, we should make a new commit. Authors and timestamps are also included in the commits alongside the message and content. Git commits are made in the branch from which we are checked out. Therefore, it’s recommended to check git status before running a commit. Any new changes should be staged before running a commit.

List commits

First, let's try to fetch all commits from the specified repository:

Request Parameters

Parameters

Type

Description

username

String

The username of the repository owner

repository

String

The name of the repository whose commits are to be listed

Press + to interact
Please provide values for the following:
ACCESS_TOKEN
Not Specified...
USERNAME
Not Specified...
REPOSITORY
Not Specified...
const endpointUrl = 'https://api.github.com/repos/{{USERNAME}}/{{REPOSITORY}}/commits';
const headers = {
Authorization: 'token {{ACCESS_TOKEN}}',
Accept: 'application/vnd.github.v3+json',
};
const options = {
method: 'GET',
headers,
};
async function GetCommits() {
try {
const response = await fetch(endpointUrl, options);
printResponse(response);
} catch (error) {
printErrors(error);
}
}
GetCommits();

In case of successful ...