Change a directory name in a Github repository remotely, directly from local Linux Git?
Solution 1
The fatal error message indicates you’re working from somewhere that’s not a clone of your git repository. So let’s start by cloning the git repository first:
git clone https://github.com/benqzq/ulcwe.git
Then enter it:
cd ulcwe
and rename the directory:
git mv local xyz
For the change to be shareable, you need to commit it:
git commit -m "Rename local to xyz"
Now you can push it to your remote git repository:
git push
and you’ll see the change in the GitHub interface.
Solution 2
No, there is no way to do this as a direct operation because of the way git is structured.
The way that git works is that it stores a copy of the entire repository, including all history, to every single location.
Github, or Bitbucket, or any other hosting provider is essentially just another copy of your git repository, with a pretty web interface on top, which is treated as a central source of truth in most workflows, however the git utility does not know this.
Changes are tracked as commits. I'm guessing that by direct operation
, you mean a way of changing the folder's name without creating a commit. While this is possible by rewriting history, I would not recommend it, especially if there are multiple people/machines with copies of the git repo, as this can lead to inconsistencies.
The easiest way to rename a folder in a git repo would be to clone it locally
git clone [url]
cd [git-folder]
If you already have a local copy of the repo, pull it to ensure you are up to date to the remote repo
git pull
Make the changes you need to locally
git mv local xyz
Which should automatically be added to the staging area by github. Then you should commit and push these changes.
git commit -m 'Renamed local to xyz'
git push
This will commit the change to your local repository, then push these changes to the remote copy of the repository, in this case, Github.
Related videos on Youtube
user9303970
Updated on September 18, 2022Comments
-
user9303970 over 1 year
This is my Git repository:
https://github.com/benqzq/ulcwe
It has a dir named
local
and I want to change its name to another name (say, fromlocal
toxyz
).Changing it through GitHub GUI manually is a nightmare as I have to change the directory name for each file separately (GitHub has yet to include a "Directory rename" functionality, believe it or not).
After installing Git, I tried this command:
git remote https://github.com/benqzq/ulcwe && git mv local xyz && exit
While I didn't get any prompt for my GitHub password, I did get this error:
fatal: Not a git repository (or any parent up to mount point /mnt/c) Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
I know the whole point in Git is to download a project, change, test, and then push to the hosting provider (GitHub in this case), but to just change a directory, I desire a direct operation. Is it even possible with Git?
Should I use another program maybe?
-
user253751 about 6 yearsNo, direct remote operations are not possible in Git. You do have to clone (download) the project, change it, then push back to the hosting provider. But how are you even using Github without having the project on your computer? Are you making all the changes through the Github web UI - that doesn't sound very convenient or efficient.
-
user9303970 about 6 yearsIn this particular case using the UI is usually quite convenient and efficient for me, the main thing I miss is the direct dir name change...
-
-
Stephen Kitt about 6 yearsNo, history is not stored as changes between commits, each commit is self-supporting. Changes between commits are re-calculated on request every time they’re needed.
-
user11153 about 6 years"all history is downloaded to every single location" - not with
git clone --depth
-
Lightness Races in Orbit about 6 yearsIn other words, it's just like any other operation on the files in your Git repository.
-
user1686 about 6 yearsHistory rewriting wouldn't be required for this -- GitHub could just generate a commit doing so. (Just as it already does when editing files directly on the website.)