Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete a folder in github, but not in local

Tags:

git

github

I know that if I want to ignore folder that I don't want to push to Github. I could use .gitignore to ignore it.

Now my situation is I had pushed the folder up to Github, now I wish I could ignore it and delete it on Github, but still want the folder in local side.

How could I achieve it?

like image 625
LiJung Avatar asked Mar 24 '13 11:03

LiJung


People also ask

Can I delete a folder in GitHub not local?

Using the git rm –cached Command We've mentioned that git rm FILE will remove files from the index and local working tree by default. However, the git rm command provides the –cached option to allow us only to remove files from the repository's index and keep the local file untouched. As we can see, the user-list.

How do I delete a folder directly from GitHub?

Browse to the directory in the repository and branch that you want to delete. In the top-right corner, click "…", and then Delete directory.

How do I remove a folder from git only?

Command line Git repository delete Just run the rm command with the -f and -r switch to recursively remove the . git folder and all of the files and folders it contains.

What happens if I delete git folder?

The folder is created when the project is initialized (using git init ) or cloned (using git clone ). It is located at the root of the Git project repository. If we delete the . git folder, the information saved by Git will be lost, and the directory will no longer act as a Git repository.


2 Answers

It seems like the --cached option of git rm is what you want.

git rm --cached fileToDelete
git commit master
git push origin master
Now add the file to .gitignore

Not tested though.

like image 133
JB Nizet Avatar answered Sep 22 '22 13:09

JB Nizet


In order for you to remove the folder or file from Github but no from you computer use this command in the following order

  1. git rm -r --cached name-of-the-folder
  2. git commit -m "insert your comment inside this quotation marks"
  3. git push origin

in case you have several branches you can do

  • git push origin master
  • git push origin branchName

EXAMPLE

  1. git rm -r --cached .vscode
  2. git commit -m "removed the .vscode folder"
  3. git push origin
like image 31
Frádely Diloné Avatar answered Sep 22 '22 13:09

Frádely Diloné