CodeBlanks Logo Icon CodeBlanks

git add

Learn to stage files with git add.

Meet the git add Command

git add is used to add working tree changes to the staging area. It does not commit the changes; it only prepares them for a commit.

git add file.txt

Staging Versus Committing

git add prepares changes for a commit. git commit saves staged changes to the repository history. These two commands serve different purposes.

git add file.txt
git commit -m "Update file"

Practice Build a Staging Command

Assign a Git command that stages a file to a string variable. The filename must be notes.txt. Print the command.

Starter code

terminal
// Sahneleme komutunu oluştur
let command;

// Komutu yazdırma işlemini tamamla

Sample solution

terminal
let command = 'git add notlar.txt';

console.log(command);

Expected output

git add notlar.txt

Questions and answers

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

1 Which command adds a change to the staging area?

  • git config
  • git commit
  • git add Correct answer
  • git status

Explanation: <code>git add</code> stages changes in the staging area.

2 Complete the Staging Command

Question
Değişiklikleri hazırlık alanına eklemek için ____ komutu kullanılır.
Answer
Değişiklikleri hazırlık alanına eklemek için git add komutu kullanılır.

Explanation: <code>git add</code> adds changes to the staging area.

3 Match the Staging Operations

Term Meaning
git add Stage changes
stage Prepare for commit
index Hold prepared changes
git commit Save the changes

All lessons in Beginner