311

I am receiving this notice when I push updates from my local instance to remote master on GitHub:

remote: This repository moved. Please use the new location [new location]

Is there a way to fix this?

0

4 Answers 4

493

The simple way is:

git remote set-url origin [updated link url https://........git]

Alternatively, if you like the long way it is:

git remote rm origin
git remote add origin [updated link]

Changing a remote's URL GitHub documentation goes into further detail.

10
  • 8
    Presumably you need to use the [email protected]:...git or similar URL if connecting using ssh? My error message listed the new https scheme URL, but it was the git@ URL that I actually needed to set as the origin. git remote show origin will tell you what URL scheme you are using currently.
    – Jason
    Commented Sep 8, 2015 at 19:26
  • 37
    git remote -v will also show what urls you have set.
    – Dusda
    Commented Oct 26, 2015 at 21:54
  • 1
    Would be better if you could swap your solutions to first one = best one. I started typing your old solution before I saw the shorter one. Commented Oct 24, 2016 at 10:45
  • 1
    I have just done that @Dodekeract because that was my reaction too! Commented Dec 23, 2016 at 13:35
  • 3
    Do not forget to add the upstream for the new repo URL. at the first push you will get an error. just use git push --set-upstream origin master.
    – GabMic
    Commented Jul 31, 2019 at 11:30
82

To check the current one:

git remote -v

Then to change it:

git remote set-url origin https://github.com/YOUR-USERNAME/YOUR-REPO.git
1
  • 1
    I did this, and the remote origin is correct but i still get this message
    – Zach Smith
    Commented Jan 13, 2021 at 5:53
14

This is an upgrade on the answers I found. Check the current one :

git remote -v

With the above command you will get a result like

origin  https://github.com/YOUR-USERNAME/YOUR-REPO (fetch)
origin  https://github.com/YOUR-USERNAME/YOUR-REPO (push)

Note this, here is the difference, it MAY NOT always be origin.

You write the command based on what you found. So if it was origin, Then you change it like :

git remote set-url origin https://github.com/YOUR-USERNAME/YOUR-REPO

If it was upstream, you change it like:

git remote set-url upstream https://github.com/YOUR-USERNAME/YOUR-REPO
0

What worked for me was breaking up my huge commit into smaller commits, starting with the file deletions.

Not the answer you're looking for? Browse other questions tagged or ask your own question.