Introduction
This article covers the following tech skills:
π§βπ» 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:
- Clone the repository and navigate it:
git clone https://github.com/labex-labs/git-playground
cd git-playground
- Configure your github account in the environment:
git config --global user.name "your-name"
git config --global user.email "your-email"
- 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"
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:
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.
π Practice Now: Create a Git Commit
Want to Learn More?
- π³ Learn the latest Git Skill Trees
- π Read More Git Tutorials
- π¬ Join our Discord or tweet us @WeAreLabEx
Top comments (0)