161

I was able to find a way on GitHub Website to rename a single file and did so with success.

I was also able to find a way to rename a whole repository and did that with success.

Does anyone know how to do this to a single directory without using command line? For reference, I am trying to change a directory named InterviewTesting (that contains source 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.

Ethan Chan
  • 153
  • 11
committedandroider
  • 8,711
  • 14
  • 71
  • 126
  • You should change your choice of correct answer, because @JonathasWalker is right. – NaN Feb 09 '17 at 17:52
  • Is it still the correct answer? I cannot do it, it only creates directory. – Quidam May 20 '17 at 02:56
  • 2
    Possible duplicate of [In a Git repository, how to properly rename a directory?](http://stackoverflow.com/questions/11183788/in-a-git-repository-how-to-properly-rename-a-directory) – Quidam May 20 '17 at 02:58

20 Answers20

227

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

Edward Anderson
  • 13,591
  • 4
  • 52
  • 48
Jonatas Walker
  • 13,583
  • 5
  • 53
  • 82
  • 69
    Well, yeah, sort of, but that's not rename, just "mkdir", and will only move *one* file from the old dir to the new. You'd still need to piss blood moving all the other files there, too, I suppose. Smells horror to me. Nice animation though! :) – Sz. Jan 18 '16 at 17:26
  • 15
    Apparently, you cannot do that anymore – Dan Chaltiel Mar 27 '16 at 15:33
  • 2
    For me it does not work as well. Instead I create file "..filename.ext" – Vityata Sep 12 '16 at 14:53
  • 3
    What hard to see here is the keystroke sequence. This was a bit confusing for me. if you press ".." then "/", it will go up a directory. Type the folder name then "/", it will go down a directory. – Spencer Jan 31 '17 at 16:23
  • 2
    Don't forgot to type "/" after the ".." – Edward Anderson Nov 21 '17 at 15:23
  • 8
    Just put your cursor at the beginning of the filename (all the way to the left) and hit backspace :] – Trev14 Jul 30 '18 at 22:19
  • The web interface has COMPLETELY changed and there is no longer an edit button. – Joshua Robison Oct 29 '20 at 07:42
  • Still working in 2022 – aloisdg Feb 16 '22 at 09:56
  • This is not an answer as it creates a new folder and moves the one file to this folder. It is currently not possible to rename a folder if it has no file or more than one file – theking2 Sep 24 '22 at 07:51
  • The best answer is from @Asef Hossain. Shows how to move an entire folder to a new location using the UI. Just drag and drop using the left menu bar. With this method you do have to move the files/folders. Then select the source control icon which allows you to type a commit message and finally commit+push. – brian_ds Jan 12 '23 at 22:55
66

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).

Hossein
  • 24,202
  • 35
  • 119
  • 224
Kevin Marin
  • 823
  • 6
  • 8
  • 6
    It's true you can't rename a folder and all of its files directly in the UI. The accepted answer does work for individual files, though you have to edit every file in the directory, moving each to a new parent folder. When the last file is removed, the old directory will disappear. – Edward Anderson Nov 21 '17 at 15:27
53

Open your github repo. Press the . key on your keyboard 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.

Drew Noakes
  • 300,895
  • 165
  • 679
  • 742
Asef Hossain
  • 531
  • 4
  • 4
  • 1
    Good to know about the code view. Best solution for the question above. – Miguel Pardal Sep 22 '22 at 17:00
  • 2
    This should be answer. It allows you to move entire directories at a time. – brian_ds Jan 12 '23 at 22:54
  • Sounds promising. What does `"Press . to open it with web vs code"` mean? – PatrickT May 09 '23 at 03:58
  • Okay, got it. That dot is the button/icon to the dev page. A quick way to it that doesn't involve clicking is to replace `https://github.com/username/reponame/` with `https://github.dev/username/reponame/` – PatrickT May 09 '23 at 04:06
  • Thank you! This was the only way I found that worked for my scenario (invalid character in folder name on Windows). – Drew Noakes Aug 28 '23 at 00:44
20

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.

Dean_CamDo
  • 333
  • 2
  • 3
14

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

Benaboki
  • 151
  • 1
  • 3
  • yea i don't even remember why i asked this question. It's much easier to do this via command line – committedandroider May 04 '18 at 22:03
  • I want to rename my git repo, never used command line, what is the precedent procedures of getting there? can you elaborate with more details? Thank you. – Choix Jun 18 '18 at 00:49
8
git mv <oldname> <newname>
git add <newname>
git commit -m "Renaming folder"
git push -u origin main
Ahmad
  • 8,811
  • 11
  • 76
  • 141
5

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.

Ambu Vijayan
  • 51
  • 1
  • 2
  • This is the correct answer, you just go edit a file and spam backspace to get to the directory you want to edit – Omar Oct 21 '22 at 01:13
3

You can do the following:

  1. Go to any file from the repository.
  2. Click the drop-down menu from the top-right of the file window.
  3. Click on Open in github.dev Github dev location
  4. When it switches to Gihub dev environment, you can rename the required folder from the explorer section.
  • If you have a new question, please ask it by clicking the [Ask Question](https://stackoverflow.com/questions/ask) button. Include a link to this question if it helps provide context. - [From Review](/review/late-answers/33090624) – coturiv Nov 07 '22 at 09:56
  • 2
    Or just replace `https://github.com/username/reponame/` with `https://github.dev/username/reponame/` – PatrickT May 09 '23 at 04:05
2

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!

Nica
  • 39
  • 3
2

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
1

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/add-and-commit@v5.1.0

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

Mudlabs
  • 551
  • 5
  • 16
0

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 )

Pratik Nabriya
  • 123
  • 1
  • 6
0

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.

0

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.

Ivan Ts
  • 31
  • 4
0

Similar to previous answer by @AsefHossain, Github has a great extension using VS Code, simply hitting shift and . at the same time (on a Mac at least). This opens a new web page window with your repo in the file viewer. You can edit and commit code here. Note, that this will commit directly to your main development branch, works great.

egolinko
  • 21
  • 1
  • 2
0

It can also be done using The [github.dev][1] web-based editor. To open your github repository using github.dev, you can either :

  • Press the . key on your repository
  • Swap .com with .dev in the URL

After your edits, you can commit your changes like described here : https://docs.github.com/en/codespaces/the-githubdev-web-based-editor#commit-your-changes

ob_dev
  • 2,808
  • 1
  • 20
  • 26
0

The question seems simple but it was quite hard for me to get the answer. I wanted to rename my folder from capital letters to small so I made sure my git configuration will catch that first. For this, I ran:

git config core.ignorecase false

Then simply rename your files in the VS code and commit them. You probably still see the old folders in the github repo. So go to the folder you're interesting in deleting and press ... button on top right and Delete directory enter image description here

Yasin Amini
  • 53
  • 11
-1

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

  • 1
    Thats the whole repository...not a sub directory. There is no way to change the name of a subdirectory of the repository – rolinger Jun 14 '19 at 20:24
-2

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.

jouell
  • 3,288
  • 1
  • 18
  • 15
-6

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?

alexander.polomodov
  • 5,396
  • 14
  • 39
  • 46