How to add changes to Staging and Commit changes in Git: Git and GitHub Tutorial – Part 4

Share on facebook
Share on twitter
Share on linkedin

Introduction

In our previous post we learned how to create and initilaize a Git repository. Now it’s time to learn the 3 stages or states that every artifact (file/dir) must go through in a git repository. They are as follows:

  1. modified
  2. staged
  3. committed

Once a file is created we usually need to modify it for whatever reasons it might be. After modification, we need to prepare the file for committing to the repository. In this stage, we mark the file as staged using the git add command. In other words we add the artifact to index or staging area. Once the artifact has been staged, we finally need to commit it so that Git safely stores it in it’s database and includes the artifact in the commit history using the git commit command

If you haven’t read the previous article of the Git & GitHub Tutorial Series, please visit here.

Adding your changes to Index

## Commands to work with

# Adds the changes to the file named "some-file" to the index
# This command is useful when you have made changes to a single file
git add some-file

# Adds all the changes in the current dir (".") to the index
# This command is useful when you have made changes to multiple files
git add .

Committing changes to repository

## Commands to work with

# Commits the changes to the repo with the mentioned message inline
git commit -m "some commit message"

# Commits the changes by opening the default git text editor
# The commit message needs to be typed in the editor
git commit -m

What’s next?

Please wait for the next article in the Git & GitHub Tutorial series.

Watch the related video for this article

Enroll in this FREE Course

Bibhash Roy

Bibhash Roy

Bibhash is a hardened Software Developer and Professional turned entrepreneur with more than two decades of rich industrial experience in Sotware Engineering & Architecting. However, he is passionate about teaching whatever he has learned in his career spanning an array of prestigious stints at large multinational Software Giants.

About Us

GoKoders is the ultimate resource to learn Programming, Spring Framework & Spring Boot, Devops and Machine Learning that can help you to build mission critical Applications.

Subscribe to our Newsletter

Recent Posts

Categories

Follow Us

Weekly Tutorial

Sign up for our Newsletter

Want to build a rock solid foundation in Git & GitHub?
Enroll in this FREE Course

Git & GitHub For Complete Beginners

Want to build a rock solid foundation in Git & GitHub?

Enroll in this FREE Course

Git & GitHub For Complete Beginners