1

I created a git repo and commited files/folder, after some time a deleted a folder from my local git folder and in try to update the repo I run the commands -

git add .
git commit -m "second commit"
git remote add origin https://github.com/trialcode/test.git
git push -u origin master

But the removed folder is still shown there in my git repo although the files were updated. Let me know what I am doing wrong with the git files/folder update.

FYI - I tried git branch -d folder_to_remove/ but it is throwing an error - error: branch 'folder_to_remove/' not found.

Trialcoder
  • 4,822
  • 8
  • 37
  • 63
  • Duplicate of [How to remove a directory in my GitHub repository?](http://stackoverflow.com/questions/6313126/how-to-remove-a-directory-in-my-github-repository) –  Jul 16 '14 at 04:56

2 Answers2

13

Vijay's answer will work, but I also want to point out an additional solution.

Normally git add won't add deleted files to your staging area (to be committed), so when you ran

git add .

you didn't actually stage any of your deleted files.

Staging deleted files with git add

If you want git add to actually stage deleted files, then you have to use the --update or -u flags:

git add --update
# Or
git add -u

Additionally, you can also use the --all or -A flag, but if I remember correctly, that flag only stages deleted files starting with Git version 2.0...or something like that. Note also that the flag will also stage untracked files, unlike -u, which only updates already-tracked files:

git add --all
# Or
git add -A

Documentation

Community
  • 1
  • 1
9

Git will have a hidden folder .git/ in your local repo directory. Everything about your local repository will be stored inside that folder.

So When You create a folder and commit, it will be stored.After that even if you delete the file or folder from your file system it will not be notified to local git repository.

To notify git that you have deleted a file or folder use the command git rm.

Try this

git rm folder_name
git commit -m "removed folder"
git remote add origin https://github.com/trialcode/test.git
git push -u origin master

Here folder_name is the filename or folder name which you wish to remove.

Vijay R.
  • 442
  • 3
  • 7