Make Selenium Easy

Git Tutorial 7 – Git Commit – Save Staging Directory Changes To Local Repository

Introduction

As a part of GIT Tutorials End To End, we will learn about another frequently used and important git command “git commit“ in this post.

We have already encountered the word “commit” in previous posts mainly when we run “git status” command but we did not understand that well. Let’s learn about it in detail in this post.

Did you know that I have started a YouTube channel as well and I need your support to make it successful. Please do watch content then comment, like, share, and obviously subscribe.

What is the “git commit” command?

If you have followed the previous posts in sequence then you must have added changes from the working directory to the staging area using “git add” command. Once we reach that step or we have staged changes (after using git add command) then we need to use git commit command.

We already know from the previous post that As per Atlassian  "git add” is the first command in a chain of operations that directs Git to “save” a snapshot of the current project state, into the commit history. Now we can say that “git commit” is the second command in above chain of operations.

The git commit command captures a snapshot of the project’s currently staged changes and creates a new commit. Please note this snapshot is committed to the local repository. I mean if we have a central repository like BitBucket etc, assosiated with the project then the commit will not push changes to the central repository automatically. You can always make changes to committed snapshots. We can have multiple commits and can refer always what was project’s status at a particular commit.

Let’s learn git commit command in action.

  1. Create an empty directory.
  2. Right-click and click on Git Bash Here.
  3. Type a git command as “git init“.
  4. Type “git status” command.
  5. Create a new file and add some content to it.
  6. Type “git status” command.
  7. Type “git add <fileName>” command.
  8. Type “git status” command.

The above steps I have covered well in my previous posts. Now we will perform git commit. Let’s execute “git commit -m <commit msg>” command. As we already know that git commit command creates a snapshot of the project’s currently staged changes and we can have multiple commits so we should provide a commit message which can help us to identify them. It is a kind of label that we give to each commit.

As we have added a file “myFile1.txt” so I have given a meaningful commit message. As git commit command already committed currently staged changes, the output of git status command shows that the working tree is clean. If we rerun the same git commit again it will not perform anything.

We can use the duplicate commit message as well but kindly give it unique so that you can understand the changes. Let’s add another line in the existing file and make a commit.

You need to add modified files tracked by git again.

We will see more about git commit in upcoming posts.

Please subscribe to my YouTube channel Retarget Common to learn from my video tutorials.

Below are important end to end tutorials for Testers:-

Selenium Tutorials

Rest Assured Tutorials

Postman Tutorials

TestNG Tutorials

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.
#ThanksForReading
#HappyLearning

Author: Amod Mahajan

My name is Amod Mahajan and I am an IT employee with 6+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went through so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning

Leave a Reply

Please wait...

Subscribe to new posts to become automation expert

Want to be notified when my new post is published? Get my posts in your inbox.

Git Tutorial 7 – Git Commit – Save Staging Directory Changes To Local Repository

by Amod Mahajan time to read: 2 min
0
%d bloggers like this: