Add/remove

Utilize common version control operations with Git

📘Cisco DevNet Associate (200-901 DEVASC)


For the DEVASC exam, you must clearly understand how Git tracks changes and how to use git add and git rm correctly. These are basic but very important commands in daily development and DevOps work.

This topic is heavily tested because version control is a core skill for automation engineers, developers, and network engineers working with infrastructure-as-code.


1. Quick Refresher: What is Git?

Git is a distributed version control system used to track changes in source code and configuration files.

In an IT environment, Git is commonly used to:

  • Store Python automation scripts
  • Store API integration code
  • Store YAML configuration files
  • Store Infrastructure-as-Code files (like Terraform or Ansible)
  • Track changes in network device configurations
  • Collaborate with other engineers

2. Understanding the Git Workflow (Very Important for Exam)

Before learning add and remove, you must understand the three main areas in Git:

1️⃣ Working Directory

This is where you edit your files.

Example:

  • Editing script.py
  • Modifying config.yaml

2️⃣ Staging Area (Index)

This is a temporary area where you prepare changes before committing.

You move files here using:

git add

3️⃣ Repository (.git directory)

This is where committed versions are permanently stored.

You move files here using:

git commit

Important Concept

Git does NOT automatically track file changes.

You must explicitly tell Git:

  • “Track this file” → git add
  • “Stop tracking this file” → git rm

This is why add and remove are critical.


3. git add – Add Files to Staging Area

Purpose

git add moves changes from:

Working Directory → Staging Area

It prepares changes for the next commit.


Basic Syntax

git add <filename>

Common Variations (Very Important for Exam)

1️⃣ Add a Single File

git add script.py

Used when you modified one specific file.


2️⃣ Add Multiple Files

git add script.py config.yaml

3️⃣ Add All Files in Current Directory

git add .

Very commonly used.

Adds:

  • New files
  • Modified files

4️⃣ Add All Changes (Tracked + Deleted)

git add -A

Stages:

  • New files
  • Modified files
  • Deleted files

For DEVASC exam, understand that:

CommandWhat It Adds
git add .New + modified files (in current directory)
git add -ANew + modified + deleted files

5️⃣ Add Only Modified/Deleted Files (Not New)

git add -u

Stages:

  • Modified files
  • Deleted files
    But NOT new files.

This difference is sometimes tested.


4. Why git add is Important in IT Environments

In real IT environments:

  • You modify a Python script that calls a REST API.
  • You update an Ansible playbook.
  • You change a CI/CD pipeline YAML file.
  • You update a network automation script.

Before committing those changes, you must stage them intentionally using git add.

This allows you to:

  • Review changes
  • Stage only specific files
  • Avoid committing unwanted files

5. git rm – Remove Files from Git

Purpose

git rm removes files from:

  • Working directory
  • Staging area
  • Repository (after commit)

It deletes a file and tells Git to stop tracking it.


Basic Syntax

git rm <filename>

Example:

git rm old_script.py

This:

  • Deletes file from local directory
  • Stages the deletion

After this, you must commit:

git commit -m "Removed old script"

6. Important Variations of git rm (Exam Relevant)


1️⃣ Remove File Only from Git (Keep Local Copy)

git rm --cached <filename>

This:

  • Stops tracking the file
  • Keeps it in your working directory

This is commonly used when:

You accidentally committed:

  • .env file
  • API keys
  • Secrets
  • Log files

Example:

git rm --cached secrets.txt

Then commit.

The file stays locally but is no longer tracked by Git.

⚠️ Very important for exam.


2️⃣ Remove Multiple Files

git rm file1.py file2.py

3️⃣ Force Remove (If Modified)

git rm -f <filename>

Used if file has uncommitted changes and Git prevents removal.


7. Difference Between rm (Linux) and git rm (Exam Trap)

If you use:

rm file.txt

You only delete it from the filesystem.

Git still thinks it exists.

You must then run:

git add -A

or

git rm file.txt

Exam concept:
Git commands must be used to properly track changes.


8. File Lifecycle in Git (Very Important)

A file in Git can be:

  1. Untracked
  2. Tracked
  3. Modified
  4. Staged
  5. Committed
  6. Removed

Workflow Example

  1. Create automation.py
  2. Run git status → shows Untracked
  3. Run git add automation.py
  4. Run git commit
  5. Modify file
  6. Run git add automation.py
  7. Run git commit
  8. Run git rm automation.py
  9. Run git commit

This full lifecycle understanding is important for DEVASC.


9. git status – Always Check Before Add/Remove

Before and after add or rm, always check:

git status

This shows:

  • Untracked files
  • Modified files
  • Staged files
  • Deleted files

The exam may give a scenario and ask what command should be used.


10. Common Exam Scenarios

Scenario 1:

You created a new YAML configuration file but Git does not see it.

Correct command:

git add filename.yaml

Scenario 2:

You deleted a file manually and want Git to recognize it.

Correct command:

git add -A

OR

git rm filename

Scenario 3:

You accidentally committed a sensitive configuration file and want to stop tracking it.

Correct command:

git rm --cached filename

Scenario 4:

You want to stage only modified files but not new files.

Correct command:

git add -u

11. Best Practices for DEVASC Candidates

  • Always run git status
  • Stage only necessary files
  • Avoid git add . blindly in production repositories
  • Use .gitignore for:
    • Log files
    • Temporary files
    • Virtual environments
    • Secret files

12. Common Mistakes (Exam Traps)

MistakeWhy It Is Wrong
Thinking git add commits filesIt only stages
Thinking rm and git rm are sameThey are different
Forgetting to commit after git rmRemoval not permanent
Assuming Git auto-tracks new filesIt does not

13. Commands You Must Memorize for the Exam

git status
git add <file>
git add .
git add -A
git add -u
git rm <file>
git rm --cached <file>
git rm -f <file>
git commit -m "message"

14. Summary for Quick Revision

git add

  • Moves changes to staging area
  • Required before commit
  • Can stage:
    • Single file
    • All files
    • Only modified files
    • Everything including deletions

git rm

  • Removes file from Git tracking
  • Stages deletion
  • --cached keeps local copy
  • Must commit after removal

Final Exam Tip

For Cisco DevNet Associate (200-901 DEVASC):

  • Understand staging vs committing
  • Understand tracked vs untracked files
  • Know difference between git add ., -A, and -u
  • Know when to use git rm --cached
  • Be comfortable reading git status output
Buy Me a Coffee