Git Ignore and Cleanup Flashcards
Q: What is .gitignore in Git?
A: A file that specifies files or patterns that Git should ignore and not track.
Q: How do you ignore all .log files in a repository?
A: Add *.log to the .gitignore file.
Q: How do you ignore a specific file, e.g., config.php?
A: Add config.php to the .gitignore file.
Q: How do you ignore an entire directory, e.g., node_modules/?
A: Add node_modules/ to the .gitignore file.
Q: How do you create a .gitignore file?
A: Create a file named .gitignore in the root of the repository and add patterns to it.
Q: How do you exclude .gitignore from being ignored itself?
A: Ensure .gitignore is not listed in .gitignore.
Q: How do you list all ignored files in a repository?
A: Use git status –ignored.
Q: What happens if a file already tracked by Git is added to .gitignore?
A: Git will continue tracking it until it is manually removed from the index.
Q: How do you stop tracking a file without deleting it from the working directory?
A: Use git rm –cached <file>.</file>
Q: How do you ignore all files in a directory except one, e.g., keep important.txt in docs/?
A: Add docs/* and !docs/important.txt to .gitignore.
Q: What is the difference between .gitignore and .git/info/exclude?
A: .gitignore is shared and tracked by Git, while .git/info/exclude is local and not shared.
Q: How do you globally ignore files across all repositories?
A: Add patterns to a global ignore file and configure it using git config –global core.excludesfile <path>.</path>
Q: How do you untrack all files listed in .gitignore?
A: Use git rm -r –cached ., then git add ., and commit the changes.
Q: What does git clean do?
A: Removes untracked files and directories from the working directory.
Q: How do you perform a dry-run of git clean to see what would be removed?
A: Use git clean -n.