Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 348
Ujjwal Singh Avatar asked Jun 04 '16 22:06

Ujjwal Singh


People also ask

Can you rename a local Git repository?

To rename any repository of your GitHub account: Go to that particular repository which you want to rename. Navigate to the settings tab. There, in the repository name section, type the new name you want to put and click Rename.

How do I rename a GitHub repository on my desktop?

On GitHub.com, navigate to the main page of the repository. Under your repository name, click Settings. Under the Repository Name heading, type the new name of your repository. Click Rename.


1 Answers

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}
like image 187
Ujjwal Singh Avatar answered Sep 22 '22 06:09

Ujjwal Singh