How to remove a directory from git repository?

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?


Remove directory from git and local

You could checkout 'master' with both directories;

git rm -r one-of-the-directories
git commit -m "Remove duplicated directory"
git push origin <your-git-branch> (typically 'master', but not always)

Remove directory from git but NOT local

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

To remove folder/directory only from git repository and not from the local try 3 simple commands.


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 named .gitignore and put that folders name into it. You can put as many as you want

.gitignore file will be look like this

/FolderName

删除目录


If, for some reason, what karmakaze said doesn't work, you could try deleting the directory you want to delete (through your file system browser), issuing the command
git add -A
and then
git commit -m 'deleting directory'
and then
git push origin master .

链接地址: http://www.djcxy.com/p/45190.html

上一篇: 使当前提交Git仓库中唯一的(初始)提交?

下一篇: 如何从git存储库中删除目录?