Moving a git repository

后端 未结 5 1813
星月不相逢
星月不相逢 2020-12-24 11:28

This question may be dumb, but I\'ve been wondering it for a while. It\'s about git repositories, but I assume it\'s the same for local repositories for other DVCS\'.

<
5条回答
  •  不思量自难忘°
    2020-12-24 12:15

    Show current remote (this is optional step of course):

    $ git remote show origin
    * remote origin
    URL: git@oldserver:project.git
    Remote branch(es) merged with 'git pull' while on branch master
    master
    Tracked remote branches
    master
    

    What we need to do is to remove current origin and add the new one:

    $ git remote rm origin
    $ git remote add origin git@newserver:project.git
    $ git remote show origin
    * remote origin
    URL: git@newserver:project.git
    Remote branch(es) merged with 'git pull' while on branch master
    master
    error: refs/remotes/origin/HEAD points nowhere!
    New remote branches (next fetch will store in remotes/origin)
    master
    

    Don’t worry about the error shown by the last command. The first pull from the origin will fix it:

    $ git pull
    From git@newserver:project.git
    * [new branch]      master     -> origin/master
    Already up-to-date.
    $ git remote show origin
    * remote origin
    URL: git@newserver:project.git
    Remote branch(es) merged with 'git pull' while on branch master
    master
    Tracked remote branches
    master
    

    I’m still fresh with Git so maybe thre’s a better way to do it but this worked for me.

提交回复
热议问题