Committing changes to the local git repository

Hi, I am data engineer from Nepal with over 3 years of professional experience and love working with ASP.NET, SQL Server and Raspberry Pis.
Search for a command to run...

Hi, I am data engineer from Nepal with over 3 years of professional experience and love working with ASP.NET, SQL Server and Raspberry Pis.
No comments yet. Be the first to comment.
In this series, we will explore git through commands and learn about commands that every developer should be aware about.
In this article, we will be looking at how you can install git on your system. After installing git on the system, we can use it to version control the directories. Installing git on a Linux Installing git on a Linux is pretty straightforward. In the...
Once we have set up our Git and the repository, we can get started with the version control. We can now work on files and directories in the repository, make changes, and commit those changes. Concepts of Staging When we create or edit an existing fi...

Git is one of the most popular version controlling system out there. It is a free and open source version controlling system. Git has become an integral part of software development. Git is a distributed version controlling system meaning multiple de...

In this article, we will be looking at how you can install git on your system. After installing git on the system, we can use it to version control the directories. Installing git on a Linux Installing git on a Linux is pretty straightforward. In the...

In the previous article, we staged the changes we made to the files. Now, we will be committing our code to make the changes permanent and make additional changes on top of them.
Once we have staged our changes, we can now use git commit command to commit the changes. Once the code is committed, git creates the snapshots of the changes which can be tracked through the change processes. Git will keep track of the author, timestamps, changes, commit hash, and message along with other details.
You can use the git commit command as follows:
$ git commit -m "Initial Commit"
Let's have a look at the above command. Here, we use the git commit command to tell git we are ready to commit the changes we have staged. The -m flag tells the commit that we will provide a commit message. We have passed "Initial Commit" after the -m flag which will tag the message to the commit.
Additionally, you can also use -a flag to stage the tracked files automatically. We would run the following command to stage and commit tracked files (including changes and deleted files).
$ git commit -am "Stage and commit"
We tend to forget some changes more often than we would like to admit. When this happens you can always make further changes, and commit the changes with another commit. But what if there is a better way to do this? Well, you can just amend the last commit using the --amend flag.
Just make the changes you missed and run the following command.
$ git commit --amend
This makes sure that the changes you have made are added to the last commit made on the git repository. You can verify the commit using git log and see that no new commits were made. You can also use --no-edit a flag if you do not want to edit the commit message. You can also use --amend flag to update your commit message without making any changes.
In this article, we learned about the git commit command and some useful flags like -a, -m and --amend. In the next article we will be diving into git remotes and explore how we can connect our local repository to Github.