CodeBlanks Logo Icon CodeBlanks

Adding a single file

Learn to stage a single file.

Stage a Single File

To stage only a specific file, write its path after the git add command. This lets you prepare one file without adding changes from other files.

git add src/app.js

Use a File Path

A file path identifies a file's location inside the project. To stage a file in a subfolder, you can write the folder names and filename together.

git add assets/logo.png

Practice Generate a Command for a Specific File

Create a command that stages the reports/monthly.csv file. Assign it to the stageCommand variable and print it.

Starter code

terminal
// Belirli dosya için komut oluştur
let stageCommand;

// Değişkeni yazdırma işlemini tamamla

Sample solution

terminal
let stageCommand = 'git add reports/monthly.csv';

console.log(stageCommand);

Expected output

git add reports/monthly.csv

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which command correctly stages only the src/app.js file?

  • git add src/app.js Correct answer
  • git add src
  • git commit src/app.js
  • git status src/app.js

Explanation: When the file's path follows the command, only the specified file is staged.

2 Complete the Single File Path

Question
git add ________________
Answer
git add ____________docs/guide.md

Explanation: Use the full path containing the folder and filename to stage a single file.

3 Match the File Path Parts

Term Meaning
git add File staging command
src/ Source code folder
assets/ Assets folder
app.js JavaScript filename

All lessons in Beginner