Git

How to Show Git Unpushed Commits

To publish files and directories from a local folder or repository to a git remote repository, the use of the git push query is common amongst developers. Pushing refers to the process of sending commits from our local git folder on Linux to a remote git folder or repository. It’s similar to the fetch query of git, except that instead of importing commits to our local system, it sends them to git remote places.

The git pulls command fetches and downloads material from a git remote folder, then updates the local folder to resemble it. A typical job in Git-based collaborative routines is integrating global upstream updates into your local git folder. We have decided to implement this article for every Linux and git user who doesn’t know about listing the unpushed commits in the Kali Linux distribution.

Let’s get started by launching the Kali Linux already configured on your Windows 10 system via the WSL utility. The Kali Linux distribution console application will be opened on your desktop showing the query area generated for the admin user i.e. “kalsoom” in this scenario.

Before going towards the main topic of execution, one needs to make sure that the Kali Linux distribution is updated already with newer utilities and free of error systems. We will be using the “update” query of Kali Linux to update it.

The “apt-get” package is used to execute this command with admin rights. Enter your admin account password upon request and tap on the Enter key to continue updating your Kali Linux system.

To avoid complexities, we have already created a git local repository in our Kali Linux system named “test”. On utilizing the list instruction of Linux, we have listed it on our console.

Let’s move within the git local repository first to see what is inside it. Use the “cd” instruction along with the repository name and you will be moved within it. On using the “ls” list query, we have got 3 different files of the “test” repository listed on our output shell i.e. new.sh, one.txt, and README.

Before checking out the unpushed commits, we need to perform some transactions on the “test” repository files. So, we have been using the “sudo rm” instruction to remove the “new.sh” bash file from the “test” repository.

After removing it, we used the “git commit” instruction with the “-m” option to commit the removal transaction on our local repository along with displaying a message. It highlighted that the deleted file is “new.sh”. We haven’t performed any push query yet, so nothing got changed at the remote repository.

Now, we will remove another file from the local “test” got repository. Using the “rm” remove command with sudo rights followed by the name of a text file “one.txt”, the action was performed.

Now, the git commit instruction will be executed again in the console with the “-m” option and the display message to be displayed. It will delete the one.txt file from our local repository but the changes on the remote repository will not be reflected until the push is used.

We have left with the single README file in a test local git repository. Let’s say, you want to delete this last file as well from your test repository. So, we will be using the sudo rights to execute the “rm” removal instruction followed by the name of a file ‘README”.

After that, we utilized the git commit command here again to commit the last transaction i.e. removal of the README file. The output is showing the 3 highlighted files which are deleted successfully. But it also shows that to reflect these changes, you must push the data to remote GitHub.

All these transactions using commit cannot work until we use the “git add” instruction and git push instruction to add and push the data to a remote repository. Now, it’s the turn of some git commands to display the unpushed commits on our Kali Linux console screen.

For this, we will utilize the git log instruction with some different options in comparison to simple git log instruction. So, we will use the “—branches”, “—not”, and “—remotes” options along with the git log instruction. These options will be used to only get the commits that are not pushed to the remote server yet according to the “—remotes” and “—not” options, with the use of a git-push instruction.

The output for the execution of this git log instruction is displaying the same 2 commits that are being performed by us just a while before. This means that both the commits have not been pushed to the remote directory of git yet and hence no updates.

The same git log file can be used with the same options while adding some other options to make its output more simple. So, we will use the “—simplify-by-decoration”, “—decorate”, and “—oneline” options to decorate the output commit and show them on a single line. In return, the execution shows us the 2 commits with their IDs and their description in one line.

Conclusion

This was all about the introduction of git push and git pull functions used to update data in a remote and local directory. After that, we performed some actions to delete files, and commit commands were used to reflect the changes. In the end, we have discussed different instructions to display the unpushed commits of git.

About the author

Kalsoom Bibi

Hello, I am a freelance writer and usually write for Linux and other technology related content