Add Files to the Staging Area (Challenge)

GitGitBeginner
Practice Now

This tutorial is from open-source community. Access the source code

Introduction

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 challenge, 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-12675{{"`Add Files to the Staging Area (Challenge)`"}} 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.

Tasks

  1. View all files in the current directory.
  2. Suppose you have made changes to the index.html and style.css files in the git-playground directory of the git-playground repository. Add these files to the staging area.
  3. 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.
  4. Alternatively, add all files with a .js extension in the src directory.
  5. View the status of the current working directory and staging area again.
  6. You can also add all changes to the staging area.
  7. View the status of the current working directory and staging area again.

This is the finished result:

Summary

In this challenge, 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.

Other Git Tutorials you may like