Skip to main content

Commit Changes

To save your changes to a Git repository, you need to commit them. Committing changes creates a snapshot of your project at a specific point in time, allowing you to track the history of your project and collaborate with others.

To commit changes to a Git repository, follow these steps:

  1. Open your terminal or command prompt on your local machine. Navigate to the directory of your Git repository using the cd command.

    Terminal
    cd path/to/repository
  2. Check the status of your repository to see which files have changed. Use the git status command to view the changes that are not yet staged for commit.

    Terminal
    git status

    The git status command will show you the files that have been modified, added, or deleted since the last commit.

  3. Stage the changes you want to commit using the git add command. This command adds the changes to the staging area, preparing them for the next commit.

    Terminal
    git add filename
    Note:

    Replace filename with the name of the file you want to stage. You can also use git add . to stage all changes in the repository.

  4. Commit the changes using the git commit command. This command creates a new commit with the changes you staged in the previous step.

    Terminal
    git commit -m "Add new feature to the project"
    Note:

    Replace "Add new feature to the project" with a meaningful commit message that describes the changes you made in this commit.

  5. Verify the commit by checking the commit history of your repository. Use the git log command to view the commit history, including the commit message, author, date, and commit hash.

    Terminal
    git log

    The git log command will display a list of commits in reverse chronological order, showing the most recent commits first.

  6. Congratulations! You have successfully committed changes to your Git repository. Your project history is now updated with the new commit, and you can continue working on your project with confidence.