17

I have a local repository (has a local remote-origin file://<remote>).
How do I change the displayed name of this repository in the Github desktop app without having to rename the repository directory name.

Problem is: C:\Project1\Website & C:\Project2\Website - both show up as Website
I want to refrain from having to have: C:\Project1\Project1-Website

I set the .git\description file - did not work.
I set the remote origin URL to <path>\Project-Website.git - did not work.
I tried git clone <path>\Project-Website.git Project-Website - did not work.

This is the mess that it causes:

Screenshot listing the duplicate repo names

Ujjwal Singh
  • 4,908
  • 4
  • 37
  • 54

4 Answers4

8

How do I change the displayed name of this repository in the GitHub desktop app without having to rename the repository directory name?

You would need to upgrade GitHub Desktop to its latest revision 2.8 (Apr. 2021):

Create aliases for repositories locally

Many developers keep more than one copy of a repository in GitHub Desktop, and the way repositories are displayed makes it tricky to differentiate between them.

In GitHub Desktop 2.8, you can create aliases for your local repositories to easily tell them apart in the list.

https://github.blog/wp-content/uploads/2021/04/GitHub-Desktop-repository-aliases.gif

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
6

UPDATE: This has been resolved now - with the "Add Alias" feature.

It turns out git itself has no provision to specify the repository name. The root directory name is the single source of truth pertaining to repository name. The .git/description though is used only by some applications like Gitweb.

Also GitHub desktop has no provision to rename the local repositories.

Workaround:

To override displayed repo names ( to be run in dev-tools: [View > Toggle developer tools] ) Best to save it as a snippet (Sources > Snippets) [unfortunately this will have to be run on each start]

function getElementByXpath(path) {
  return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}

function overrideRepoNames(repoNames) {
  for (x in repoNames) {
    getElementByXpath('//*[@id="__ListRow_1-' + (parseInt(x) + 1) + '"]/div/div[2]/span/span').innerHTML = repoNames[x].replace(new RegExp('\\\\','g'), ' \\ ')
  }
}

repoNames = ['Ujnotes\\Website\\Framework', 'WCode\\Website\\Framework', 'WCode\\Website\\interim', 'WCode\\Location\\interim', 'Ujnotes\\Website\\interim', 'WCode\\Location\\Paper', 'WCode\\Website\\Project', 'WCode\\Android\\Project', 'WCode\\Windows\\Project', 'WCode\\Location\\Project', 'Ujnotes\\Website\\Project'];

getElementByXpath('//*[@id="desktop-app-toolbar"]/div[1]/div/div/button').addEventListener('click', function(event) {
  setTimeout(function() {
    if(getElementByXpath('//*[@id="foldout-container"]') != null)
        overrideRepoNames(repoNames)
  }, 50);
});

This is the result:

Local repo list with renamed entries

Here is AHK script to automate the execution of the script snippet at launch:

Run, "%LocalAppData%\GitHubDesktop\GitHubDesktop.exe"

winWait, GitHub Desktop
sleep, 1000
send, {CTRLDOWN}{SHIFTDOWN}i{SHIFTUP}{CTRLUP}
sleep, 2000
send, {CTRLDOWN}{SHIFTDOWN}p{SHIFTUP}{CTRLUP}
sleep, 2000
send, {BACKSPACE}
sleep, 100
send, {!}
sleep, 100
send, {ENTER}
sleep, 500
send, {CTRLDOWN}{SHIFTDOWN}i{SHIFTUP}{CTRLUP}
Ujjwal Singh
  • 4,908
  • 4
  • 37
  • 54
3

You have to rename directory in this Method

  1. First You have to Close every app that using the relevant directory
  2. Then Rename the Folder
  3. After that Open Github Desktop and CLICK "Locate" then Browse Folder:

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
hexhad
  • 1,139
  • 12
  • 14
0

Non of the above is the right answer. Only putting the name in .git/description (own first line) has it done for me!

Reason: I don't why but VSCode has changed my repository names to completely wrong ones. So there must be another point where GitHub Desktop takes the names.

perhelion
  • 132
  • 1
  • 8