How to view unpushed Git commits

Overview

Git is a free and open-source distributed version control system.

In this shot, we'll learn how to view git commits that have not been pushed to the remote repository.

We can view the unpushed git commits using the git command. It will display all the commits that are made locally but not pushed to the remote git repository.

git log origin/master..HEAD

Example

Let's take a look at an example.

Commands

Below are the commands we will be using:

# create a file and write content with the tee command
echo "This is a test file" | tee test.txt
# add all files in current folder to git staging area
git add .
# commit all changes
git commit -m "Added test file"
# view unpushed git commits
git log origin/master..HEAD
Command list

Execute the given commands sequentially in the terminal below:

Terminal 1
Terminal
Loading...

Explanation

  • We added a file named test.txt to a test repository.
  • We used git add . to stage the newly created file for the next commit.
  • We committed the changes using git commit but did not push them to the remote repository.
  • We displayed the unpushed git commits using git log origin/master..HEAD.

We can view the unpushed commits in the final output of the terminal.

New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources