Skip to content
Fix Code Error

How to remove a directory from git repository?

March 13, 2021 by Code Error
Posted By: Anonymous

I have 2 directories on my GitHub repository. I’d like to delete one of them. How could I do that without deleting and re-creating entire repository?

Solution

Remove directory from git and local

You could checkout ‘master’ with both directories;

git rm -r one-of-the-directories // This deletes from filesystem
git commit . -m "Remove duplicated directory"
git push origin <your-git-branch> (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
Answered By: Anonymous

Related Articles

  • Why do I have to "git push --set-upstream origin "?
  • Why call git branch --unset-upstream to fixup?
  • Difference between git checkout --track…
  • Checkout another branch when there are uncommitted…
  • Why do git fetch origin and git fetch : behave differently?
  • Git workflow and rebase vs merge questions
  • Git Using Remote Branch
  • How do I make a Git commit in the past?
  • How do I delete a Git branch locally and remotely?
  • What is a tracking branch?
  • How to create the branch from specific commit in…
  • Why does git perform fast-forward merges by default?
  • What's the difference between "git reset" and "git…
  • Git: Create a branch from unstaged/uncommitted…
  • How can I reconcile detached HEAD with master/origin?
  • What exactly does the "u" do? "git push -u origin…
  • Why did my Git repo enter a detached HEAD state?
  • How does origin/HEAD get set?
  • Various ways to remove local Git changes
  • Retrieve specific commit from a remote Git repository
  • Git merge with force overwrite
  • How can I switch to another branch in git?
  • Your configuration specifies to merge with the from…
  • Git, How to reset origin/master to a commit?
  • In plain English, what does "git reset" do?
  • Git submodule head 'reference is not a tree' error
  • git pull while not in a git directory
  • How can I find the location of origin/master in git,…
  • Git push won't do anything (everything up-to-date)
  • Why does Git say my master branch is "already up to…
  • Git - Pushing code to two remotes
  • How can I move HEAD back to a previous location?…
  • How do I clone a single branch in Git?
  • What is git tag, How to create tags & How to…
  • How to pull in changes from skeleton sub-repository…
  • Merge, update, and pull Git branches without using checkouts
  • What is "git remote add ..." and "git push origin master"?
  • git bring some "older" changes to a new branch after…
  • Git fetch remote branch
  • How do you stop tracking a remote branch in Git?
  • Git merge master into feature branch
  • How to recover stashed uncommitted changes
  • Why do I need to do `--set-upstream` all the time?
  • git pull from master into the development branch
  • Why do I need to explicitly push a new branch?
  • Change a Git remote HEAD to point to something…
  • How to download a branch with git?
  • What are the differences between git remote prune,…
  • Homebrew install specific version of formula?
  • git lfs push to github failure on Ubuntu 18.04
  • moving committed (but not pushed) changes to a new…
  • How to clone ('fork') your own personal GitHub repo…
  • How do you get git to always pull from a specific branch?
  • master branch and 'origin/master' have diverged, how…
  • How do I 'overwrite', rather than 'merge', a branch…
  • Delete all local git branches
  • How to cherry pick a range of commits and merge into…
  • Git push rejected after feature branch rebase
  • Rename master branch for both local and remote Git…
  • Git submodule update
  • How to clone all remote branches in Git?
  • git push says "everything up-to-date" even though I…
  • XMLHttpRequest cannot load ✘✘✘ No…
  • Checking out Git tag leads to "detached HEAD state"
  • Updates were rejected because the tip of your…
  • In Git, what is the difference between origin/master…
  • git status shows modifications, git checkout --…
  • “tag already exists in the remote" error after…
  • Need to reset git branch to origin version
  • How to git reset --hard a subdirectory?
  • Git branching: master vs. origin/master vs.…
  • How to track untracked content?
  • Push git commits & tags simultaneously
  • How do I rename both a Git local and remote branch name?
  • How to list branches that contain a given commit?
  • error: pathspec 'test-branch' did not match any…
  • Make: "nothing to be done for target" when invoking…
  • Update a local branch with the changes from a…
  • How do I add files and folders into GitHub repos?
  • git error: failed to push some refs to remote
  • How to commit my current changes to a different…
  • How to use terminal commands with Github?
  • Move the most recent commit(s) to a new branch with Git
  • Git "error: The branch 'x' is not fully merged"
  • Remote branch is not showing up in "git branch -r"
  • Why does git status show branch is up-to-date when…
  • Finding a branch point with Git?
  • Git: Merge a Remote branch locally
  • git switch branch without discarding local changes
  • Remove tracking branches no longer on remote
  • Git pull a certain branch from GitHub
  • How do I revert a Git repository to a previous commit?
  • How to modify existing, unpushed commit messages?
  • How to revert multiple git commits?
  • Squash the first two commits in Git?
  • Why is processing a sorted array faster than…
  • ExpressJS How to structure an application?
  • Git push: "fatal 'origin' does not appear to be a…
  • No 'Access-Control-Allow-Origin' header is present…
  • How to keep a git branch in sync with master

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

Using boolean values in C

Next Post:

TypeError: a bytes-like object is required, not ‘str’ when writing to a file in Python3

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error