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 (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 如何刪除不需要的Packages目錄.txt ---------- 1 git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch packages/" HEAD 2 rm -r .git/refs/original/ 3 git reflog expire --all 4 git gc --aggressive --prune 5 git push -f 如何刪除不需要的(packages, bin跟obj)目錄.txt ---------- 1.1 git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch packages/" HEAD 1.2 git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch bin/" HEAD 1.3 git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch obj/" HEAD 2 rm -r .git/refs/original/ 3 git reflog expire --all 4 git gc --aggressive --prune 5 git push -f ref to http://stephanvs.com/removing-an-accidentally-commited-packages-folder-from-git/ ---------- Removing an accidentally commited packages folder from Git history 21 April 2015 on git, rewrite history Sometimes it's unfortunate these things happen to us. Though luckily because we're using Git we can fix almost any issue we get ourselves into. Today it's the fact that someone accidentally commited the packages folder into git and pushed the commits to GitHub. Generally it's a bad idea to store large binary files in Git. So how can we remove them? Just deleting the folder and commiting the deleted files is not enough, because the files will still live on in the history of the git repo. Anytime we clone the repo, we'll have to pull in these binary files again, such a waste of time/bandwidth. Anyhow, without further ado; here's the steps to rewrite history (in the quite literal sense I'm afraid) 1 Remove packages folder from old git commits. git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch packages/" HEAD Note: If you have more branches in which this packages folder lives, also apply the --all argument. 2 Update your .gitignore file to include the packages folder, or better yet, download one from http://gitignore.io like a default one for Visual Studio development. Which also has a nice exception to the build folder under packages, which is used as an MSBuild target. 3 Clean up the internal git database. rm -rf .git/refs/original/ git reflog expire --all git gc --aggressive --prune These commands will cleanup the temporary info left over from the filter-branch and run garbage collection. 4 Force push to make everyone happy again. git push -f