Git
Git Overview Video
Git Will Finally Make Sense After This
How to remove unwanted files from a git repo AFTER adding a .gitignore
Requirement: You need to have git CLI installed on your computer (Found in Company Portal)
- Navigate to your local repo location on your disk
- Right Click in the repo and select "Open in Terminal". A Windows Powershell window will open already navigated to your repo location.
- Run the following command:
git ls-files -ci --exclude-standardls-files: Show information about files in the index and the working tree
-ci: Show only ignored files in the output. Must be used with either an explicit -c or -o.
--exclude-standard: Add the standard Git exclusions: .git/info/exclude, .gitignore in each directory, and the user’s global exclusion file.This returns a list of all the individual items in your repo that match an ignore instruction in your .gitignore file. If this command returns nothing, then your repo is perfectly compliant with your .gitignore file.
- Check over the returned files and ensure that you are wanting them to be removed from your git repo.
- Run the following command:
git ls-files -ci --exclude-standard | ForEach-Object { git rm --cached $_ }The
ForEach-Objectcmdlet performs an operation on each item in a collection of input objects. Within the script block, use the$_variable to represent the current object. The script block is the value of the Process parameter. The script block can contain any PowerShell script.
rm: Remove files from the working tree and from the index
--cached: Use this option to unstage and remove paths only from the index. Working tree files, whether modified or not, will be left alone.
This command runs the git command "rm" on each object that was returned from the first part of the script and removes it from your repo. - Run Step 3 again to check that the files were properly removed.
-
git commit -am "Removed unwanted files marked in .gitignore" -
git push origin master