Skip to Content

Microsoft AZ-400: How to Permanently Remove Sensitive File from GitHub Repository?

Learn the correct Git commands to purge a sensitive file from your GitHub repository. Ensure your repositories remain secure by properly deleting and force pushing changes.

Table of Contents

Question

You manage source control by using GitHub.

You have a file named Data.txt that contains sensitive data. A user pushes Data.txt to a repository.

You need to purge the file from the repository.

Which two commands can you use? Each correct answer presents a complete solution.

NOTE: Each correct solution is worth one point.

A. git checkout
git reset -hard -pathspec data.txt
B. git checkout
git clean -d data.txt –force
C. bfg –delete-files data.txt
git push –force
D. git rm data.txt
git push –force
E. git filter-repo –invert-paths –path data.txt
git push origin –force –all
F. git revert -edit data.txt
git push -force

Answer

To permanently remove a sensitive file like Data.txt from a GitHub repository, you can use the following two commands:

C. bfg –delete-files data.txt
git push –force

E. git filter-repo –invert-paths –path data.txt
git push origin –force –all

Explanation

Both options C and E provide complete solutions for purging a file from the repository’s history.

Option C uses the BFG Repo-Cleaner tool, which is designed to remove unwanted files from Git repository history. The command `bfg –delete-files data.txt` removes all instances of the file “data.txt” from the repository. Following this, `git push –force` forces the changes to the remote repository, overwriting its history.

Option E uses the `git filter-repo` command, which is a powerful tool for rewriting Git history. The `–invert-paths` flag ensures that all paths except the ones specified are kept, and `–path data.txt` specifies the file to be removed. After the history is rewritten, `git push origin –force –all` force pushes all refs to the remote repository, effectively purging the sensitive file.

Options A, B, D, and F are incorrect because they do not completely remove the file from the repository’s history. They only remove the file from the current state of the repository, but the file would still be accessible in previous commits.

Microsoft AZ-400 certification exam assessment practice question and answer (Q&A) dump including multiple choice questions (MCQ) and objective type questions, with detail explanation and reference available free, helpful to pass the Microsoft AZ-400 exam and earn Microsoft AZ-400 certification.