Leaving Github, how to change the origin of a Git repo?

GitVersion ControlGithubDreamhost

Git Problem Overview


I'm hosting a project in Github, but now I purchased a plan with Dreamhost that includes shell access and Git.

      Github [Origin]
       /         \
  pull/           \pull
     /push     push\
    /               \  
Laptop           Dreamhost
(cloned)          (cloned)

I would like to delete my repo from Github, and starting push directly to DH.

How do I change origin in my Laptop, and should I delete the origin in Dreamhost?

Git Solutions


Solution 1 - Git

git remote rename origin github
git remote add origin <DreamHost-git-URL>
# test and make sure the DreamHost origin works properly for fetch and push
git remote rm github

I prefer using the 'git remote' command instead of screwing about with the .git/config file by hand.

Solution 2 - Git

The easiest way is:

$ git config remote.origin.url <Dreamhost-git-URL>

You show the remotes after this:

$ git remote -v
origin Dreamhost-git-URL (fetch)
origin Dreamhost-git-URL (push)

Solution 3 - Git

The easiest way is to edit your .git/config file on your laptop. Simply search for your github url and replace it with the one from DreamHost. Make sure that your ssh public key is set on Dreamhost. Now you can push origin master and you will have populated your dreamhost repository.

You can delete origin on dreamhost but there is no need.

Also, ensure that the repository that is there is bare. By default, you cannot push to non-bare repositories.

Solution 4 - Git

The best way is to git remote set-url origin <new-url>

Solution 5 - Git

The easiest way is to edit your .git/config file, which lists where the origin lives. You can test it by running a git fetch

You can delete the remote references on the Dreamhost side if you like, in the same file.

Solution 6 - Git

why not simply :

git remote remove origin

git remote add origin <Dreamhost-git-URL>

git push -u origin --all --tags

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBen OrozcoView Question on Stackoverflow
Solution 1 - GitcleeView Answer on Stackoverflow
Solution 2 - GitOctavi FornésView Answer on Stackoverflow
Solution 3 - GitAdam DymitrukView Answer on Stackoverflow
Solution 4 - GitslashingweaponView Answer on Stackoverflow
Solution 5 - GitYann RaminView Answer on Stackoverflow
Solution 6 - GitgjambetView Answer on Stackoverflow