147

I created a local GIT repository on Windows. Let's call it AAA. I staged, committed, and pushed the contents to GitHub. git@github.com:username/AAA.git

I realized I made a mistake with the name.

On GitHub, I renamed it to git@github.com:username/BBB.git

Now, on my Windows machine, I need to change git@github.com:username/AAA.git to git@github.com:username/BBB.git because the settings are still trying to "push" to git@github.com:username/AAA.git but I need to push to git@github.com:username/BBB.git now.

How could I do that?

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
user169320
  • 1,694
  • 2
  • 12
  • 16

4 Answers4

273
git remote set-url origin <URL>
animuson
  • 53,861
  • 28
  • 137
  • 147
hallucinations
  • 3,424
  • 2
  • 16
  • 23
  • 7
    This seems to work fine. If you're copying an existing repo to a new one, however, you'll need to follow this up with git push origin master. – Josh Jul 25 '12 at 18:21
  • I have added a similar solution at the bootom. http://stackoverflow.com/a/15784886/1177575 – Abibullah Rahamathulah Apr 03 '13 at 10:29
  • I like this way, it fits conveniently in a workflow where i copy a .git/config from another repo when I initialize a new one. – Merlin Aug 06 '21 at 19:11
132

The easiest way to tweak this in my opinion (imho) is to edit the .git/config file in your repository. Look for the entry you messed up and just tweak the URL.

On my machine in a repo I regularly use it looks like this:

KidA% cat .git/config 
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
    autocflg = true
[remote "origin"]
    url = ssh://localhost:8888/opt/local/var/git/project.git
    #url = ssh://xxx.xxx.xxx.xxx:80/opt/local/var/git/project.git
    fetch = +refs/heads/*:refs/remotes/origin/*

The line you see commented out is an alternative address for the repository that I sometimes switch to simply by changing which line is commented out.

This is the file that is getting manipulated under-the-hood when you run something like git remote rm or git remote add but in this case since its only a typo you made it might make sense to correct it this way.

wonea
  • 4,783
  • 17
  • 86
  • 139
jkp
  • 78,960
  • 28
  • 103
  • 104
62

One more way to do this is:

git config remote.origin.url https://github.com/abc/abc.git

To see the existing URL just do:

git config remote.origin.url
Jian
  • 10,320
  • 7
  • 38
  • 43
25

Take a look in .git/config and make the changes you need.

Alternatively you could use

git remote rm [name of the url you sets on adding]

and

git remote add [name] [URL]

Or just

git remote set-url [URL]

Before you do anything wrong, double check with

git help remote
AsimRazaKhan
  • 2,154
  • 3
  • 22
  • 36
Steinbitglis
  • 2,482
  • 2
  • 27
  • 40