I have 2 directories on my GitHub repository. I'd like to delete one of them. How could I do that without deleting and re-creating entire repository?
Browse to the directory in the repository and branch that you want to delete. In the top-right corner, click "…", and then Delete directory. Review the list of files. Depending on your permissions and the branch protection rules, choose to either commit the change directly or propose the change using a pull request.
Execute the following command: git rm --cached path/to/file . Git will list the files it has deleted. The --cached flag should be used if you want to keep the local copy but remove it from the repository.
You may use the –r option in the Git rm command for removing a folder. Any files contained in the folder are also removed. The –r option in rm command allows recursive removal if you provide a leading directory name.
You could checkout 'master' with both directories;
git rm -r one-of-the-directories // This deletes from filesystem git commit . -m "Remove duplicated directory" git push origin <your-git-branch> (typically 'master', but not always)
As mentioned in the comments, what you usually want to do is remove this directory from git but not delete it entirely from the filesystem (local)
In that case use:
git rm -r --cached myFolder
Steps to remove directory
git rm -r --cached FolderName git commit -m "Removed folder from repository" git push origin master
Steps to ignore that folder in next commits
To ignore that folder from next commits make one file in root folder (main project directory where the git is initialized) named .gitignore and put that folder name into it. You can ignore as many files/folders as you want
.gitignore file will look like this
/FolderName
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With