ð§âðŧ New to Git or LabEx? We recommend starting with the Quick Start with Git course.
Git is a popular version control system that allows developers to track changes made to their codebase. One of the essential features of Git is the staging area, which allows developers to selectively choose which changes to commit. In this lab, you will learn how to add files to the staging area using Git.
Skills Graph
%%%%{init: {'theme':'neutral'}}%%%%
flowchart RL
git(("`Git`")) -.-> git/BasicOperationsGroup(["`Basic Operations`"])
git/BasicOperationsGroup -.-> git/add("`Stage Files`")
subgraph Lab Skills
git/add -.-> lab-12761{{"`Add Files to the Staging Area`"}}
end
Add Files to the Staging Area
You have been working on a project stored in a Git repository named https://github.com/labex-labs/git-playground. You have made some changes to the codebase and want to commit these changes to the repository. However, you only want to commit specific changes and not all the changes you have made. To do this, you need to add the files to the staging area.
You will make some changes in the git-playground directory:
View the status of the current working directory and staging area, including information on which files have been modified, which files have been added to the staging area, etc:
git status
Alternatively, add all files with a .js extension:
git add *.js
View the status of the current working directory and staging area again:
git status
You can also add all changes to the staging area:
git add .
View the status of the current working directory and staging area again:
git status
This is the finished result:
Summary
In this lab, you learned how to add files to the staging area using Git. You can use the git add command to add specific files or a fileglob to add multiple files to the staging area. Adding files to the staging area allows you to selectively choose which changes to commit to the repository.
We use cookies for a number of reasons, such as keeping the website reliable and secure, to improve your experience on our website and to see how you interact with it. By accepting, you agree to our use of such cookies. Privacy Policy