Hello, everyone. In our daily development process, whether it’s the end of a development phase or the end of a day’s work, we need to perform local project repository commits for our code. This operation not only saves the code versions but also helps with future tracking work. It is a necessary habit to develop. In this article, we will learn how to commit the completed code versions to the local project repository for storage and recording.
For this operation, I am using IntelliJ IDEA version 2022.2.3 (Community Edition).
Add a new code file to the index of the local project repository.
1.Move the mouse over the project folder, right-click, and then choose “New” -> “File” from the menu that pops up to create a new file. (Note: If you are working on a Java project development, please choose “Java Class”)

2.Enter the new file name and press the “Enter” key on the keyboard.

3.In the popped-up dialog, it asks if we want to add the new file to the local project index. Here, we click on “Add”. (Note: If you want to skip this prompt in the future and automatically add new files to the index, you can check the “Don’t ask again” checkbox at the bottom left.)

4.Now you can see that the newly created file has turned green, indicating that this file has been added to the index of the local project repository. (Note: In IntelliJ IDEA, a green file indicates that the file is in a state ready to be committed.)

To commit the completed code file version to the local project repository
1.Add some text to the newly created file.

2.Click on the ✔️ icon in the top-right Git shortcut bar or press 【ctrl+k】 on the keyboard.

3.At this point, you will see that the left-side project view has switched to the Commit tab. At the top of the window, it displays the affected files in this commit. In the middle, it indicates how many files have been added, modified, or deleted. At the bottom, you can input your commit message. Here, I want to remind everyone to leave a clear and informative message for each commit, describing the purpose of the changes made. This not only helps others understand the changes but also prevents yourself from forgetting the reason behind the code changes in the future, thus enhancing development efficiency. After writing the commit message, click on the 【Commit】 button.

4.After the commit is completed, you will see a clear commit notification at the bottom left corner.

5.Finally, let’s click on the “Project” tab or press “Alt+1” on the keyboard to return to the project view.

Supplemental Note: Regarding automatically pushing to the remote repository after version commits
Observant users may have noticed that on the file commit page, there is a “Commit and Push” button located to the right of the “Commit” button. When clicking this button, IntelliJ IDEA will automatically perform the commit and push the committed changes to the remote repository. While this feature is very convenient, it is essential to exercise caution when using it frequently, as it can lead to unnecessary risks in the remote repository.
In the next article, I will provide several principles as prerequisites for using the “Commit and Push” button. I hope these principles can help you avoid unnecessary troubles and make more informed decisions when utilizing this feature.




