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:
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
Please wait for the next article in the Git & GitHub Tutorial series.