Creating Files with Git Command: A Shell Tutorial

The git commit command offers significant features, such as including all altered files with the -a option, excluding new untracked files. Additionally, you can create a commit command with a displayed message using the -m “message” option. Lastly, to display the state of both the working and staging areas, use the git status command.

Saving files or a group of files in Git differs significantly from the process in a file editor. To preserve the most recent versions of a Git project, we need to execute the following instructions:

  1. The command to add changes to a Git repository.
  2. The current status of the Git repository can be checked by using the command “git status”.
  3. Making a commit using Git.

.

The git add command acts as a messenger between the user and git. It instructs git to include the changes in the upcoming stage. However, these changes do not have an impact on the repository until the git commit command is executed.

The “Git status” command exhibits the current status of both the working area and staging area. It lists the tracked and untracked files in the working directory. This command is advantageous because it allows the user to review their changes before committing unwanted modifications.

The Git commit command is used to capture changes and is frequently used in conjunction with git add. These two commands typically go hand in hand. There are several important options available for the git commit command.


  • -a
  • This commit comprises all the altered files at present, but any untracked files are not impacted.


  • -m “message
  • A command is created for committing with a message displayed. The command will open a text editor that is configured locally, by default.

  • The text to be paraphrased is simply the word “message.
  • This command is a shortcut that merges the -a and -m options together.


  • –amend
  • By selecting this option, the user can modify the most recent commit without creating a new one. In case the user forgets to specify a commit message using -m, they will be prompted with the message from the previous commit command.

The following images depict the functioning of the aforementioned commands.

To initiate the process, a python file needs to be created.

In our initial commit, we utilized various git commands like git add, git status, and git commit.
Image:

Modifying and saving the Number.py file within IDLE.

In our second commit, we utilized the commands git add, git status, and git commit once more. Additionally, the attached image (msdt_img1) depicts this process.

The fundamental commands in Git are git add and git commit, which serve distinct purposes. git add is responsible for selecting the changes that should be staged for the next commit command, while git commit captures these staged changes as a snapshot. To determine the current state of the staging area, the git status command is utilized.

Frequently Asked Questions