...

/

Use git add Interactively

Use git add Interactively

Learn to micromanage the staging area and better carve our commits when many changes are made.

The git add command comes with an interactive mode. In this mode, we can choose to stage only a part of a file, down to the level of lines.

Understand git add -i

First of all, let’s create two files, file1 and file2, in the new directory and commit them. Then, we add a few lines in both files after the initial commit according to the statements given below.

The following commands are already in the terminal below. Click the terminal to run them:

 $ mkdir folder
 $ cd folder
 $ git init
 $ echo 'This is file1' > file1
 $ echo 'This is file2' > file2
 $ git add .
 $ git commit -am 'files added'
 $ cat > file1 << END
 > Good change
 > This is file1
 > Experimental change
 > END
 $ cat > file2 << END
 > All good
 > This is file2
 > END
Access this course and 1400+ top-rated courses and projects.