Gitlab is one of the popular open-source code repositories that are free for programmers to add their codes and programs online. You will get online storage with GitLab, which also permits you to inspect the codes. It not only helps programmers but is useful for non-programmers as well. When you uploaded a program to the GitLab repository, and then you want to delete folder in Gitlab repository later for any reason, the web provides you a user-friendly way to do so.
Today, we discuss how you can delete folder in Gitlab repository that you don’t want to be in your GitLab. Check out do it
How To Delete Folder in GitLab Repository
If you make a folder by mistake, then you would like to delete the folder in GitLab repository. Sometimes, deleting a folder is a bit tricky as compared to creating one. This is how you delete the folder
Using ‘git rm’ Command
When you want to delete a folder or directory, this command works.
git rm -r <directory_name>
with this, you can delete the folder or directory that you want. It removes all the content from the repository.
Let’s take an example. If you have a folder or directory named ‘del_folder’ that you want to delete from the repository.
$ ls del_folder tmp.txt
And, you want to delete it. You can type the below code
$ git rm -r del_folder rm 'del_folder/tmp.txt'
To completely delete the del_folder folder or directory from GitLab, you need to commit as well as push the removal of the folder to remover from the repository.
Follow this to delete
$ git commit -m "removed del_folder directory" [main b89f021] removed del_folder directory 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 del_folder/tmp.txt $ git push origin main
This can easily remove the folder from the GitLab repository
Keep the folder in the Filesystem
If you want to keep the folder or directory in the local filesystem and remove the trace from the remote repository, then you can use the ‘cached’ option with the ‘git rm’ command. Check out the command
$ git rm -r --cached del_folder
The code can cause the del_folder directory to still be removed from the filesystem of the team members for the remote repository. The file will remain only in the local machine’s filesystem when we execute the command.
We have discussed how to delete folder in GitLab repository. An exemplary scenario has been discussed to show the exact code that you can try to delete the folder or directory from GitLab. You can just follow the above-mentioned codes but use the name you have for your folder in the repository.
With that, I hope you can code efficiently!
If you need any assistance, feel free to drop a comment below.