While working on large development team projects in Git, it is important to keep track of changes to ensure that all team members are aware of the modifications made to the project. After modifying the project, they send/push those modifications to the GitHub repository. However, you may sometimes want to review the changes made before pushing them to the remote repository. Viewing unpushed commits allow users to ensure changes and identify issues and bugs.
This write-up will explain:
How to List Git Commits of Current Branch That Have Not Pushed to Remote “origin” Yet?
To display all commits of the current branch that have not been pushed to the “origin” yet, different commands can be used, such as:
Example 1: Listing Unpushed Commits of the Current Branch Using “git log origin/<branch-name>..HEAD” Command
List all the unpushed commits of the current Git branch by running the given-provided command:
In the below output, all the unpushed commits of the “master” branch between “origin/master” and “HEAD” can be seen:
Example 2: Listing Unpushed Commits of the Current Branch Using “git log @{u}..” Command
The following command can also be used to display the unpushed commits of the current branch:
Here, the “@{u}” option is used to list the commits that exist locally but not upstream:
Moreover, to view the unpushed commits of the current branch in one line, utilize the “–oneline” option in the same command:
The below output only shows the SHA-hash and commit message of the unpushed commits:
How to List Git Commits of All Branches That Have Not Pushed to “origin” Yet?
To list commits of all available branches that have not been pushed to the “origin” yet, various commands can be utilized, such as:
Example 1: Listing Unpushed Commits of All Branches Using “git log –branches –not –remotes” Command
Write out the provided command to display commits of all branches that have not been pushed to the “origin” yet:
The below output shows the unpushed commits of “master” and “feature” branches:
Example 2: Listing Unpushed Commits of All Branches Using “git log –branches @{u}..” Command
To view the commits of all branches that exist locally but not upstream, execute the following command:
Moreover, to view all commits in one line, use the “–oneline” option with the same command:
That was all about listing unpushed commits in Git repository.
Conclusion
To display the commits of the current branch that have not been pushed to the remote repository, the “git log origin/<branch-name>..HEAD” and “git log @{u}..” commands can be used. Furthermore, to list the unpushed commits of all branches, utilize the “git log –branches –not –remotes” or “git log –branches @{u}..” command. Moreover, you can use the “–oneline” option with these commands to display commits in one line. This write-up explained the procedure to list the commits that have not been pushed to the GitHub repository yet.