DEV Community

Cover image for Create a Git Commit: Mastering Version Control with Git
Labby for LabEx

Posted on

Create a Git Commit: Mastering Version Control with Git

Introduction

This article covers the following tech skills:

Skills Graph

πŸ§‘β€πŸ’» New to Git or LabEx? We recommend starting with the Quick Start with Git course.

Git is a popular version control system used by developers to manage their code changes. One of the essential features of Git is the ability to create commits, which are snapshots of the code at a particular point in time. In this lab, you will learn how to create a Git commit.

Create a Git Commit

You have made some changes to your code and want to save them as a snapshot in your Git repository. However, you don't want to save all the changes you made, only the ones that are relevant to the current feature or bug fix. How can you create a commit containing only the relevant changes?

For this lab, let's use the repository from https://github.com/labex-labs/git-playground, follow these steps:

  1. Clone the repository and navigate it:
   git clone https://github.com/labex-labs/git-playground
   cd git-playground
Enter fullscreen mode Exit fullscreen mode
  1. Configure your github account in the environment:
   git config --global user.name "your-name"
   git config --global user.email "your-email"
Enter fullscreen mode Exit fullscreen mode
  1. Add "hello,labex" to the README.md file, add it to the staging area and commit it with the message "Update README.md":
   echo "hello,labex" >> README.md
   git add .
   git commit -m "Update README.md"
Enter fullscreen mode Exit fullscreen mode

The -m option allows you to specify a commit message. Make sure the message is descriptive and explains what changes the commit contains.

This is the result of running the git log command:

<result>

Summary

Creating a Git commit is an essential part of the development process. It allows you to save snapshots of your code and keep track of the changes you make over time. By following the steps outlined in this lab, you can create a commit containing only the relevant changes and add a descriptive message to explain the changes made.

MindMap


πŸš€ Practice Now: Create a Git Commit


Want to Learn More?

Top comments (0)