Mastering Git at Matillion. Unpushed Commits

Welcome back to our Git series, where we delve into various features and functionalities that make version control with Git both powerful and efficient. In our previous discussions, we've covered essential concepts like branching, merging, and hard resets. Today, we'll focus on a more nuanced aspect of Git: unpushed commits. We'll explore why you might want to view unpushed commits, how to retrieve this information both in the Data Productivity Cloud and using Git commands, and some useful alternatives to keep you informed about your unpushed commit history.

Why View Unpushed Commits?

In a collaborative development environment, understanding the state of your local repository compared to the remote repository is crucial. Unpushed commits refer to commits present in your local branch but not yet shared with the remote repository. Viewing unpushed commits is important for many reasons, including:

  • Impact Assessment: By examining unpushed commits, you can understand the potential impact your push action will have on the remote repository. This is particularly important when working on shared branches, as your changes might affect other team members' work.
  • Error Correction: Viewing unpushed commits helps to spot mistakes or unnecessary commits before they reach the remote repository, giving you the opportunity to amend changes with new commits. 

Viewing your unpushed commits acts as a local, high-level review of sorts, allowing you to check that you are about to share the work you expect to be sharing, without needing to go back over all the code or pipeline changes you have made. The messages you write for each commit are important because they provide a high-level description of the changes you’ve made, and they are what you’ll be reading when reviewing your unpushed commits.

Unpushed Commits in the Data Productivity Cloud

We will soon allow users to see their unpushed commits in the Data Productivity Cloud. We expect it to look something like this, but we might change it based on user feedback.

As you can see, this provides a high-level review of the changes that are about to be pushed to share with collaborators on your project.

How to Retrieve Unpushed Commits using Git commands

Git provides straightforward commands to help you view unpushed commits. One of the most common commands is git log, which allows you to display a filtered list of commits. To see unpushed commits, you can use the following command (in this example, we’re using the main branch, but that can be switched out for any other branch):

git log origin/main..HEAD

 

This command compares the commit history of your current branch (HEAD) with the remote main branch (origin/main). It opens an interactive ui, allowing you to scroll to see older commits. It lists all commits that are present in your local branch but not on the remote main branch, starting with the latest, displaying commit hash, author, date and commit message.

Alternatives and Similar Commands

In addition to git log, there are other commands that can provide similar insights into your commit history and differences between branches:

git diff: This command shows the differences in file contents between two branches or commits. To see the differences between your local branch and the remote main branch, you can use:

git diff origin/main..HEAD

 

This command will display the differences between your current local branch and the remote main branch, highlighting additions and deletions in your files.

git cherry: This command helps you see which commits are present in your current branch but not in the upstream branch. Use it as follows:

git cherry -v

 

This provides a succinct list of unpushed commits displaying hashes and commit messages instead of providing the interactive UI with additional metadata.

Summary

Understanding unpushed commits is helpful for maintaining a smooth and error-free development workflow. By regularly checking your unpushed commits, you can review changes, assess the impact of your push, and correct errors before they reach the remote repository. Using commands like git log, git diff, and git cherry, you can stay informed about the state of your local repository relative to the remote, ensuring that your contributions are well-managed and integrated smoothly.

Stay tuned for our next installment, where we'll explore more advanced Git features and tips to optimize your development process. Until then, happy committing and Git Good with the Data Productivity Cloud!

Catch up on

Part One: Commit, Push, and Pull. 

Part Two: Branching 

Part Three: Exploring Common Branching Strategies 

Part Four: An In-Depth Guide To Merging

Part Five: Understanding Hard Reset 

Part Seven: Uncommitted Changes 

Bryns Jones
Bryns Jones

Senior Engineering Manager

Bryns Jones is a Senior Engineering Manager working with the DataOps team at Matillion