How to List Commits Not Pushed to the Remote Repository in Git

John Wachira Mar 11, 2025 Git Git Log
  1. Using Git Log to View Unpushed Commits
  2. Using Git Diff to Check Unpushed Commits
  3. Using Git Status to Check Pushed Commits
  4. Conclusion
  5. FAQ
How to List Commits Not Pushed to the Remote Repository in Git

In the world of version control, Git is a powerhouse that helps developers manage their code efficiently. One common scenario developers face is needing to check which commits have not yet been pushed to the remote repository. This can be crucial for ensuring that your local changes are properly tracked and that you don’t accidentally miss pushing important updates.

In this article, we’ll explore various methods to list those unpushed commits in Git. Whether you’re a seasoned developer or just starting, understanding how to manage your commits effectively will streamline your workflow and enhance collaboration with your team. Let’s dive into the commands that will help you identify those unpushed commits with ease.

Using Git Log to View Unpushed Commits

One of the simplest ways to see the commits that haven’t been pushed to your remote repository is by using the git log command. This command provides a detailed history of your commits, and with the right options, it can specifically show you the commits that are local but not yet pushed.

Here’s how you can do it:

git log origin/main..HEAD

Output:

Get All Commits Between origin/main and HEAD

This command compares your current branch with the remote branch (in this case, origin/main). The origin/main..HEAD syntax tells Git to show commits that exist on your current branch (HEAD) but not on the remote branch (origin/main).

You can replace main with the name of your branch if you’re working on a different one. This method is straightforward and gives you a clear view of what’s pending to be pushed.

Using Git Diff to Check Unpushed Commits

Another effective method to see which commits have not been pushed is by using the git diff command. While git log gives you a list of commits, git diff allows you to see the actual changes made in those commits. This can be particularly useful if you want to review what you’ve done before pushing.

Here’s how you can use it:

git diff origin/main..HEAD

Output:

diff --git a/yourfile.py b/yourfile.py
index e69de29..d95f3ad 100644
--- a/yourfile.py
+++ b/yourfile.py
@@ -1,0 +1,10 @@
+def new_function():
+    print("This is a new function")
+
+new_function()

This command shows the differences between your current branch and the specified remote branch. The output displays the specific changes made in your files, which can help you decide whether you’re ready to push or need to make additional adjustments.

The git diff command is particularly useful for code reviews, allowing you to see exactly what will be pushed to the remote repository. As with the git log command, you can replace main with your branch name to tailor the command to your needs.

Using Git Status to Check Pushed Commits

If you’re looking for a quick way to see the status of your commits, the git status command is invaluable. While it doesn’t directly list unpushed commits, it does inform you about the state of your local branch in relation to the remote branch.

Here’s how to use it:

git status

Output:

On branch main
Your branch is ahead of 'origin/main' by 2 commits.
  (use "git push" to publish your local commits)

When you run git status, it provides a summary of your current branch, including how many commits you are ahead of the remote branch. If you see a message indicating that your branch is ahead, it means you have local commits that haven’t been pushed yet.

While this command doesn’t show the specific commits, it serves as a quick reminder to push your changes. For more detailed information, you can combine it with git log or git diff for a comprehensive view.

Conclusion

Managing your commits effectively in Git is essential for maintaining a smooth workflow and ensuring that your code is up to date in the remote repository. By using commands like git log, git diff, and git status, you can easily identify which commits haven’t been pushed yet. Each of these commands serves a unique purpose, whether you need a list of commits, a review of changes, or a quick status check. With these tools at your disposal, you’ll be better equipped to handle your version control tasks, collaborate with your team, and keep your projects organized. Happy coding!

FAQ

  1. How can I see all my commits in Git?
    You can use the command git log to view all your commits in the current branch.

  2. What does it mean if my branch is ahead of the remote branch?
    It means you have local commits that have not yet been pushed to the remote repository.

  3. Can I see changes in specific files that haven’t been pushed?
    Yes, you can use git diff origin/main..HEAD to see changes in specific files before pushing.

  1. How do I push my commits to the remote repository?
    You can use the command git push origin main to push your local commits to the remote repository.

  2. Is there a way to view unpushed commits in a graphical interface?
    Many Git GUI tools, like GitKraken or SourceTree, provide visual representations of your commits, including unpushed ones.

Enjoying our tutorials? Subscribe to DelftStack on YouTube to support us in creating more high-quality video guides. Subscribe
Author: John Wachira
John Wachira avatar John Wachira avatar

John is a Git and PowerShell geek. He uses his expertise in the version control system to help businesses manage their source code. According to him, Shell scripting is the number one choice for automating the management of systems.

LinkedIn

Related Article - Git Log