1

I want to rename my Github repository. Say old name is foo and I want to rename to bar

I understand how to rename the repository on the github site.

Github also advises doing the following on the local machine:

In addition to redirecting web traffic, all git clone, git fetch, or git push operations targeting the previous location will continue to function as if made on the new location. However, to reduce confusion, we strongly recommend updating any existing local clones to point to the new repository URL. You can do this by using git remote on the command line:

git remote set-url origin new_url

Question: Do I need to change the repository directory on my local machine manually? Or if I do a git pull will it automatically change the name on my local machine.

I found some old answers to this question (before github made some changes) but, in reviewing the Github documentation and googling I can't find a satisfactory answer to my question. so this is NOT a duplicate question

Thanks in advance.

Windstorm1981
  • 2,564
  • 7
  • 29
  • 57
  • Are you referring to the local repository's new `remote` or are you referring to the name of the directory on your local machine? – Andrew Fan Jul 12 '18 at 19:05
  • You do not need to change your local directory after you changed the `remote`. A `git pull` will just use the remote. If you do a `git clone` on a different location the repo will be checked out with the new name used as subdirectory. However - once again to avoid confusion - you could change local dir name to match the repo name, manually :) – Arnold Schrijver Jul 12 '18 at 19:10
  • @AndrewFan the name of the directory on my local machine. – Windstorm1981 Jul 12 '18 at 19:22

3 Answers3

1

Going off of your comment, it seems that you are concerned about the name of the directory on your local machine. In this case, you are free to name it whatever you want - the name of the directory containing the repository has no impact on the repository itself, as long as the specified remote within .git is accurate.

For updating the remote on your local machine to match your new repository on GitHub, refer to GitHub User Documentation

Andrew Fan
  • 1,313
  • 5
  • 17
  • 29
0

If I understand correctly, you're wondering whether you need to change the old repository URL (git@github.com:user/foo.git) to new URL (git@github.com:user/bar.git)

In that case, the simple answer is yes you do need to change that.

As your git clone link is now changed to the new repository and if you create a new repository that happened to have the old repository name all git commands will confuse and push and pull wrong data to/from wrong repository.

As for your question does git pull will do that for you, unfortunately no as this remote URL is hardcoded in the .git/config file and you can simply edit that and replace the link with new one without running any git commands.

[remote "origin"]
        url = git@github.com:user/foo.git
        fetch = +refs/heads/*:refs/remotes/origin/*
Prav
  • 2,785
  • 1
  • 21
  • 30
  • Hope that helps – Prav Jul 12 '18 at 19:12
  • Actually my question was about naming/renaming the local version of the repository when the I change the repository on Github (and therefore url). But thanks for your reply. Helps me learn regardless – Windstorm1981 Jul 13 '18 at 15:36
0

Another approach is to rename the remote GitHub repository from command-line, using the new gh repo rename command (from gh 2.3.0, Dec. 2021)

cd /path/to/local/repo
gh rename newName

It does also update your remote 'origin' URL: no need for a git remote set-url origin https://github.com/<you>/<newName>, it is done for you.

The root folder of the repository can then be rename if you want (but it does not matter for Git)

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