How to rename a directory/folder on GitHub website?

GitFileGithubDirectoryRename

Git Problem Overview


I was able to find a way on GitHub Website to https://github.com/blog/1436-moving-and-renaming-files-on-github">rename</a> a single file and did so with success.

I was also able to find a way to https://stackoverflow.com/questions/13909398/how-to-rename-a-github-hosted-repository">rename</a> a whole repository and did that with success.

Does anyone know how to do this to a single directory without using https://stackoverflow.com/questions/11183788/in-a-git-repository-how-to-properly-rename-a-directory">command line? For reference, I am trying to change a directory named InterviewTesting (that contains src files, etc) to something else. I tried doing it the single file way. enter image description here
But this didn't allow me to change the name of the directory (InterviewTesting), only the actual file name.

Git Solutions


Solution 1 - Git

Actually, there is a way to rename a folder using web interface.

1) Type a folder name followed by slash to go down into a subfolder. 2) Type dot dot, then slash, to jump upwards one directory. 3) Use the backspace key to edit the parent directory's name.

See https://github.com/blog/1436-moving-and-renaming-files-on-github

Solution 2 - Git

There is no way to do this in the GitHub web application. I believe to only way to do this is in the command line using git mv <old name> <new name> or by using a Git client(like SourceTree).

Solution 3 - Git

You can! Just press edit as per @committedandroider's original post and then hit backspace with your cursor at the start of the filename. It will let you then edit the folder. When done hit forward slash to then edit the filename again.

Solution 4 - Git

I had an issue with github missing out on some case sensitive changes to folders. I needed to keep migration history so an example of how I changed "basicApp" folder in github to "basicapp"

$ git ls-files
$ git mv basicApp basicapp_temp
$ git add .
$ git commit -am "temporary change"
$ git push origin master
$ git mv basicapp_temp basicapp
$ git add .
$ git commit -am "change to desired name"
$ git push origin master

PS: git ls-files will show you how github sees your folder name

Solution 5 - Git

Open your github repo. Press . to open it with web vs code. Rename there. Stage and commit the changes.

This will work better than the other options, as it will do the rename for directories which contain multiple other directories i.e. directories with subdirectories within them.

Solution 6 - Git

git mv <oldname> <newname>
git add <newname>
git commit -m "Renaming folder"
git push -u origin main

Solution 7 - Git

If you have GitHub Desktop, change the names of the directories on your computer and then push the update from your desktop to your github account and it changes them there. :)

Hope it helps!

Solution 8 - Git

Just edit a file inside the folder, click on file name and press backspace continuously. That will move to the cursor to the folder name and you can edit it. It can cause problems with hyperlinks.

Solution 9 - Git

You could use a workflow for this.

# ./.github/workflows/rename.yaml
name: Rename Directory

on:
  push:

jobs:
  rename:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - run: git mv old_name new_name
      - uses: EndBug/[email protected]

Then just delete the workflow file, which you can do in the UI

Solution 10 - Git

If you want to try it with the Github web: (and don't want to move individual files manually)

  1. Download the 'zip' for a directory. (Repeat for all directories/folders)

  2. Unzip all the directories/folders on your pc. (don't touch the internal contents of these folders)

  3. Rename these folders on your pc, such that, you precede the name of the folder name with '1. or 2. or 3. and so on' (in order that you want them to appear... eg: if u want some folder to appear first, change its name from 'xyz' to '1. xyz')

  4. Upload all these directories back on Github Web.

By doing this, all the contents of your directories/folders will remain intact and in the same order as they were... just the Directories/Folders themselves will be ordered as per the number you used while naming it in Step 3.

I found this easier and quicker than moving all individual files from one directory to other.

Example - (how it would appear on Github Web)

Before : (alphabetically ordered)

abc
jkl
xyz

After :

  1. xyz
  2. jkl
  3. abc

Solution 11 - Git

For all I know, there is no way you can do this from the GitHub web interface.

Here is how I was successfully able to do it -

Step 1: Rename in your local. In your local path, give command $ git mv old-name new-name.

Now it will be renamed in your local path.

Step 2: Staging. Give command $ git add .

Step 3: Commit. Use command $ git commit -m "add your comment" https://github.com/repo-name/branch-name.git

Step 4: Push. $ git push
or
$ git push https://github.com/repo-name/branch-name.git branch-name

(Instead of everytime specifying the big URL, you can use the alias "origin" or whatever you like. But first you need to give this command in the beginning $ git remote add origin https://github.com/repo-name/branch-name.git )

Solution 12 - Git

The best way to change the folder directory in GitHub is to work with GitHub Desktop. You can clone your repository using GitHub desktop. The folders will normally appear as Windows folders and you can play around with them (Like Renaming, Moving, Cutting, etc). Once done, commit and push the changes through GitHub Desktop, and it's done.

Solution 13 - Git

Now you can "open in github.dev editor" your repository. In repo page press Ctrl k to open command pallete and type > to show commands. First command are Open in github.dev editor. This will jump to MS Visual Studio Code in browser with opened this repository. Using file explorer you might rename files and folders and then commit changes.

Solution 14 - Git

Go into your directory and click on 'Settings' next to the little cog. There is a field to rename your directory.

Solution 15 - Git

As a newer user to git, I took the following approach. From the command line, I was able to rename a folder by creating a new folder, copying the files to it, adding and commiting locally and pushing. These are my steps:

$mkdir newfolder 
$cp oldfolder/* newfolder
$git add newfolder 
$git commit -m 'start rename'     
$git push                             #New Folder appears on Github      
$git rm -r oldfolder
$git commit -m 'rename complete' 
$git push                             #Old Folder disappears on Github  

Probably a better way, but it worked for me.

Solution 16 - Git

Go to that directory/folder and then click on the setting. In the section of "Repository name" simply rename it.

Solution 17 - Git

I changed the 'Untitlted Folder' name by going upward one directory where the untitled folder and other docs are listed.

Tick the little white box in front of the 'Untitled Folder', a 'rename' button will show up at the top. Then click and change the folder name into whatever kinky name you want.

See the 'Rename' button?

See the 'Rename' button?

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioncommittedandroiderView Question on Stackoverflow
Solution 1 - GitJonatas WalkerView Answer on Stackoverflow
Solution 2 - GitKevin MarinView Answer on Stackoverflow
Solution 3 - GitDean_CamDoView Answer on Stackoverflow
Solution 4 - GitBenabokiView Answer on Stackoverflow
Solution 5 - GitAsef HossainView Answer on Stackoverflow
Solution 6 - GitAhmadView Answer on Stackoverflow
Solution 7 - GitNicaView Answer on Stackoverflow
Solution 8 - GitAmbu VijayanView Answer on Stackoverflow
Solution 9 - GitMudlabsView Answer on Stackoverflow
Solution 10 - GitHarsh MamaniaView Answer on Stackoverflow
Solution 11 - GitPratik NabriyaView Answer on Stackoverflow
Solution 12 - Giteisenerz108View Answer on Stackoverflow
Solution 13 - GitIvan TsView Answer on Stackoverflow
Solution 14 - GitXornackView Answer on Stackoverflow
Solution 15 - GitjouellView Answer on Stackoverflow
Solution 16 - Gituser45297View Answer on Stackoverflow
Solution 17 - GitWenxiao LuView Answer on Stackoverflow