In the last post of the series, we covered "Git Add" command to stage changes. Today we are going to discuss "How to commit that staging changes to Git repository", which you will need to perform every time working with it.

 

Let's continue learning about the command "git commit" today with the parameters that you need to learn. Stay tuned to read more and more posts on Git basic series.

 

How to save changes to Git repository (www.kunal-chowdhury.com)

 

As we discussed in the last post, the git add and git commit commands compose the fundamental Git workflow. These are the two very basic commands that every Git user needs to learn and perform, irrespective of the collaboration model that the team follows. These commands are used to commit new versions/changes of a project into the repository’s history.

 

First of all, you add/edit/delete your files in the working directory. When you’re ready to save, the git add command (that we discussed in the last post) adds the changes in the working directory to the staging area. The staging area is a group of related changes into a single snapshot before actually committing it to the project history. When you are happy with the staged snapshot, you need to commit it to the actual project history with the command git commit, which we will discuss here.

 

Here's the basic commands that you need to learn and remember to commit staging changes to the repository:

 

Record changes to the repository:

$ git commit

 

Record changes to the repository with a commit message:

$ git commit -m <message>

 

Automatically stage files that have been modified and deleted:

$ git commit –a                                 # ignores new files, you have not told Git to commit

 

Use the interactive patch selector to chose changes to commit:

$ git commit -p

 

Commit by using an existing commit message (opens editor):

$ git commit -c

 

Commit by using an existing commit message and authorship:

$ git commit -C

 

Take the commit message from the given file:

$ git commit -F <file>

 

Add Signed-off-by line at the end of commit message:

$ git commit -s

 

Was this post useful? If you came to this page by searching online about git basics or git tutorials, please have a look into my other blog posts. Subscribe to the RSS feed or the email newsletter to keep yourself updated.

 

 

 

Have a question? Or, a comment? Let's Discuss it below...

Thank you for visiting our website!

We value your engagement and would love to hear your thoughts. Don't forget to leave a comment below to share your feedback, opinions, or questions.

We believe in fostering an interactive and inclusive community, and your comments play a crucial role in creating that environment.