Deleting a Local GitHub Repository
When a user clones a Git repository from Github using the command git clone <url>, they get a copy of the remote repo on their local computer so that they can work on it on their current working directory where the repo got cloned without directly making changes on the remote repository.
If you want to delete a local Github Repository that was cloned from to local computer without touching or making any changes to the Remote GitHub repository then follow the commands below:
Step 1: Go into your project file
rm -rf <repository_folder>.git
With the deletion of the ‘.git’ file, this will delete the .git file that contains a log of the commit history, its information, and also remote repository address from the working directory. We can think of this deletion as when we do git init to initialize the current working directory as Git directory, with the above command we are just reverting it back to not being a Git directory.
Then what about the files and folder in the present working directory?
This has to be deleted using the following set of command:
Step 2: (Optional if you want to initialize working directory to another GitHub Repository See Additional steps below):-
Go to the directory where the project is present (Note: Don’t go inside the project file).
rm -rf <folder_name>
What are rm and rf commands?
- In Linux, the user can delete/remove directories using rmdir or rm, in the above case we have made use of rm which is used to remove non-empty directories, unlike rmdir which is used to remove empty directories.
- This command is used to remove non-empty directories and all the files in the directory without being prompted if a directory or a file in the current working directory is write-protected (this case is very common when working on forked repository from GitHub) and the user is prompted to provide Y (for yes) to confirm the deletion of the write-protected file. Now using -rf with rm is effective as it can skip part of the user being prompted every time.
Suppose you want to initialize (git init) a new Github repository, and then add it to a new remote repository and then start adding and committing to the files being added from the current working directory.
- Make sure that the current working directory is the directory that needs to be pushed to the open-source platform (GitHub).
- git init
- git remote add origin https://github.com/user/repo.git
- git push -u origin master
Deleting the Repository from GitHub Website
Step 1: Navigate to your project
Step 2: Go to the settings option on the top right corner like the image above, and navigate down to the danger zone
Step 3: Go and click on the delete this repository button and after which you will be prompted to make sure you are deleting and all these action will permanently affect the repository, in the box type your-username/project-name (replace it with yours).
You may also be prompted to type in the GitHub password.
Following these steps will make sure you have completely deleted the repository from the local PC as well as the GitHub site.
Here we are going to delete a particular file from our github using Github. This feature can be useful when we have by ,mistake added few files in our project but we no longer need that.
Deleting the File from GitHub Website
Step 1: Navigate to your project
Step 2 : Browse to the file in your repository that you want to delete.
At the top of the file, click on the Delete Icon.
Step 3: At the bottom of the page, type a short, meaningful commit message that describes the change you made to the file
Then it will show a alert like this that the File successfully deleted.