Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I migrate a local git repository to github?

I have a git repository (with a github remote).

Then, I deleted the repository in github.

I want to recreate the git repository in github with full history (i.e. branching, commit and merging history).

How do I achieve it?

I had tried creating a new repository via web UI, cloning it, copying files one by one but it is too timeconsuming.

like image 959
Edward Aung Avatar asked Apr 17 '26 17:04

Edward Aung


1 Answers

(i'm going to use git.example.com here instead of GitLab, as there is nothing specific to GitLab, except probably the possibility to create a a git repository via the webinterface; but these days, there are plenty of different providers with the same functionality)

  1. create a new git repository via the webinterface, e.g. https://git.example.com/bfg/frobnozzel.git

  2. create a local bare clone of your (local) repository (in this example closing into /tmp/new-frobnozzel.git:

     git clone --bare /path/to/local/repository /tmp/new-frobnozzel.git
    
  3. in the newly created bare-clone, change the remote to the new github repository:

     cd /tmp/new-frobnozzel.git
     git remote set-url origin [email protected]:bfg/frobnozzel.git
    
  4. push your entire repository to the new remote:

     cd /tmp/new-frobnozzel.git
     git push --mirror origin
    
  5. (optionally) switch your working repository to use the newly created remote repository as the main upstream, use:

     cd /path/to/local/repository
     git remote set-url origin [email protected]:bfg/frobnozzel.git
    

    you might want to do an initial synch just to be sure that everything is working (git pull)

Btw, there's also some Github documentation that covers this.

like image 125
umläute Avatar answered Apr 19 '26 12:04

umläute