Windstorm1981
Windstorm1981

Reputation: 2680

Rename Github Repository

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.

Upvotes: 1

Views: 2265

Answers (4)

fereidoun mianji
fereidoun mianji

Reputation: 1

To rename a repo on git that is cloned to your folder (project) on your local drive (with the same name of course) while preserving the connection between them follow these steps.

1- Rename your remote repo on GitHub/GitLab: Go to your repo settings → Rename it to

2- Rename the local folder on your machine directly on the folder name or in bash: mv

3- Now, in a local terminal go into the renamed local folder and update Git’s remote URL using: cd <path to the folder's new name> git remote set-url origin <new_repo_url>

Note: don't forget to replace <new_repo_url> with the new repo URL from GitHub/GitLab, which includes the updated name.

4- Finally, you might want to verify the connection is h: git remote -v

If it shows the correct new URL, we're all set!

Upvotes: 0

VonC
VonC

Reputation: 1329532

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)

Upvotes: 0

Andrew Fan
Andrew Fan

Reputation: 1321

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

Upvotes: 1

Prav
Prav

Reputation: 2894

If I understand correctly, you're wondering whether you need to change the old repository URL ([email protected]:user/foo.git) to new URL ([email protected]: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 = [email protected]:user/foo.git
        fetch = +refs/heads/*:refs/remotes/origin/*

Upvotes: 0

Related Questions