GIT: REMOVING/REPLACING DIRECTORIES

January 16, 2019 Off By carlos


Ever need to replace or remove a directory in GitHub without replacing the entire repository? Its simple.

Remove A Directory

  1. git rm -r directory-name
  2. git commit -m “Remove directory name”
  3. git push origin master

Replace A Directory

First update the local files. Example, if you have a directory named ‘test’ and you want to replace all the files on GitHub with the current local files only.

  1. git rm -r –cached directory-name
  2. git commit -m “Remove duplicated directory”
  3. git push origin master

By using the –cached flag, this will remove only the directory on GitHub and not your local copy.

Then….

  1. git add “directory-name”
  2. git commit -m “Re-uploaded Directory”
  3. git push