23

How do I fix the path of my local git repo after move?

previous local location: /C/website
new local location: /C/Projects/website
remote location: git@bitbucket.org:username/website.git

I moved my git repository from one folder /website to another /projects/website and now I get an error:

user@Thinkpad /C/Projects/website (master)
$ git push
fatal: 'C:/website' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Is there any way to fix this without having to re-clone the project? I tried:

$ git init
Reinitialized existing Git repository in c:/Projects/website/.git/

It that did nothing and I got the exact same error again when I tried to push.

Edit:

I ran: git config remote.origin.url C:/Projects/website. Now when I commit after changing files I get the following reply:

user@Thinkpad /C/Projects/website (master)
$ git commit -m "added something"
[master e163ad9] added something
 0 files changed
 create mode 100644 something

user@Thinkpad /C/Projects/website (master)
$ git push
Everything up-to-date
Whitecat
  • 3,882
  • 7
  • 48
  • 78
  • 2
    OK, this is getting really confusing. What is your local repo, what is the remote? – fge Jan 22 '13 at 19:05
  • Whitecat: did you, by any chance, move the directory and files, but not enter the new directory in your terminal emulator? (the error message kinda suggests this). @fge: yeah, I'm confused too… – knittl Jan 22 '13 at 19:08
  • Thanks a ton for the help guys. My knowledge of git is now expanded and I am moving forward! – Whitecat Jan 22 '13 at 19:19

3 Answers3

55

Run git config -e and change the address of the remote, to the correct remote location. In your case that will be url = git@bitbucket.org:username/website.git This command will open for editing the .git/config file of the repository.

(thanks to @Richard for the command)

Shortcut command:

git config remote.origin.url git@bitbucket.org:username/website.git
fge
  • 119,121
  • 33
  • 254
  • 329
1

You have to update the origin remote to the new url:

git remote set-url origin '/C/Projects/website'


If you just move a local clone, you don't have to do anything to update the pointers to bitbucket or other hosting services. Just move the folder including everything (the .git directory is essential).

knittl
  • 246,190
  • 53
  • 318
  • 364
  • This did not change the effect of the commit not working. It still says "Everything up-to-date" – Whitecat Jan 22 '13 at 18:42
  • @Whitecat: if I read your question correctly, you are pushing the repository to itself? What is the current working directory? – knittl Jan 22 '13 at 18:45
  • I want to be pushing the project to my repository 'git@bitbucket.org:username/website.git' – Whitecat Jan 22 '13 at 18:46
  • 1
    @Whitecat: `git remote set-url origin …` (`… 'git@bitbucket.org:username/website.git'`) – knittl Jan 22 '13 at 18:52
  • That last line made the difference. I did move everyting including the .git folder. Can you edit your answer to say what I actually did to fix it? I am still confused as to what was wrong. – Whitecat Jan 22 '13 at 18:54
  • What was wrong, that you edited the url of the `origin` remote in the first place. It does not need to be changed. My comment only showed you, how to _undo_ your problematic change. – knittl Jan 22 '13 at 18:56
  • The only time I edited the origin at all was with yours or @Richard 's line of code. But then I am confused as to what was the original problem and how I fixed it. – Whitecat Jan 22 '13 at 18:59
  • Because I thought, you had moved the remote repository, not the repository itself. There was never any need to do anything (except moving the files) – knittl Jan 22 '13 at 19:02
  • But I did move the whole directory including the .git folder. That prompted the original question, and error. And by executing: `git config remote.origin.url c:/projects/website`, `git remote set-url origin '/C/Projects/website'` and `git remote set-url origin … (… 'git@bitbucket.org:username/website.git')` my problem was fixed. I don't think that was the correct solution. But for some reason it did the trick. – Whitecat Jan 22 '13 at 19:06
  • I found a problem! My url = "..." some how initially got confused. It was not set to `git@bitbucket.org:username/website.git`. I don't know when that happened. – Whitecat Jan 22 '13 at 19:14
0

If you used SmartGit you can change repository url by this way

open smartGit and double click on your repository and go to menu Remote>Properties.. and set new repository path to path or url.

Shaishab Roy
  • 16,335
  • 7
  • 50
  • 68
  • The questioner wanted to move his *local* repository. So do I. Your instructions worked great for updating the remote repository (which in my case had also moved), but locally it's still checking out to the old location. – Rebeccah Apr 15 '16 at 01:27