Moving repositories from outside to github and making everything work again.

I am abandoning my longtime git repository and moving the project to github.

I have successfully imported the git, and it appears to be correct and complete.

I and others have local clones of the repository and I am seeking advice as to the best practices for migrating the clones.

IIUC, “git remote set-url origin https://github.com/USERNAME/REPOSITORY.git” should do the trick. Will that work correctly, and is there any way to force a “synchronization check” that will verify that the clone has a correct image of the new origin?

Hey @charlesunixpro, help’s arrived!

If you’ve fully imported the repository to GitHub (checking online helps with this!), I’d actually suggest deleting your local copy and then cloning the new GitHub version:

$ cd ..
$ rm -rf <project-name>
$ git clone https://github.com/user/repo.git

If it’s a large repository, though, that might not be ideal. Instead, you can always change the URL for  origin :

# Check the current URL
$ git remote get-url origin
➜ https://git.itspugle.ga/github-community.git

# Set ORIGIN to the new GitHub URL
$ git remote set-url origin https://github.com/itspugle/github-community.git

# Verify the change
$ git remote get-url origin
➜ https://github.com/itspugle/github-community.git

Here’s some more info on Git Remotes: https://git-scm.com/docs/git-remote :slightly_smiling_face:

Cheers!

Delelting and recloning would kill the stash, unpushed branches and unpushed commits. I beleive.

After more research, I think I found an answer for the second part of my question: verifying local/origin synchronization.

First, run ‘git fsck --full --strict’ on the local repository clone; this will verify that it is internally consistent.

Second, compare the commit hashes on the branch heads:

      git show-ref --heads | sort -k 2 > /tmp/gitls_l

      git ls-remote --heads | sort -k 2> /tmp/gitls_r

      <your_favorite_diff_tool> /tmp/gitls_l /tmp/gitls_r

If the commit hashes match, then the entire branch matches, by definition.

1 Like