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:
| Command | What It Adds |
|---|---|
git add . | New + modified files (in current directory) |
git add -A | New + 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:
.envfile- 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:
- Untracked
- Tracked
- Modified
- Staged
- Committed
- Removed
Workflow Example
- Create
automation.py - Run
git status→ shows Untracked - Run
git add automation.py - Run
git commit - Modify file
- Run
git add automation.py - Run
git commit - Run
git rm automation.py - 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
.gitignorefor:- Log files
- Temporary files
- Virtual environments
- Secret files
12. Common Mistakes (Exam Traps)
| Mistake | Why It Is Wrong |
|---|---|
Thinking git add commits files | It only stages |
Thinking rm and git rm are same | They are different |
Forgetting to commit after git rm | Removal not permanent |
| Assuming Git auto-tracks new files | It 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
--cachedkeeps 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 statusoutput
