How do I rename a local-only repository on 'GitHub desktop' - without renaming repository directory
Asked Answered
P

4

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

Publicness answered 4/6, 2016 at 22:13 Comment(4)
Have you tried navigating to the repository using explorer and renaming it through the native file finding application?Kutaisi
@BrianaSwift that is what I want to avoid. Presently I have project\website and want to refrain from project\project-websitePublicness
Is this what you're asking? #2042493Kutaisi
Yes but specific to the GitHub desktop appPublicness
L
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://static.mcmap.net/file/mcmap/ZG-AbGLDKwfnZ7-ocV9QWmYvXe/wp-content/uploads/2021/04/GitHub-Desktop-repository-aliases.gif

Lafollette answered 28/4, 2021 at 21:37 Comment(1)
Great news! This lingered for too long.. but glad.that it's finally done.Publicness
P
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}
Publicness answered 5/6, 2016 at 16:43 Comment(0)
M
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:

Minnaminnaminnie answered 7/2, 2020 at 19:4 Comment(0)
M
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.

Maritamaritain answered 3/9, 2020 at 11:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.