56

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?

0

6 Answers 6

127
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.

7
  • 3
    I agree. I consider the format of .git/config an implementation detail, I always use the tools like git remote and git config to make sure I don't screw up the syntax. Jun 10, 2010 at 15:10
  • 1
    Oh +1 because I like this. But you should add further infos how to migrate the tracking branches afterwards...
    – hurikhan77
    Jun 12, 2010 at 19:45
  • 2
    I had to add git config branch.master.remote origin. It seems like git changed that variable as a side effect of the remote rename. Jul 12, 2011 at 21:41
  • 5
    I had to run following commands: git config branch.master.remote origin git config branch.master.merge refs/heads/master Feb 15, 2012 at 18:29
  • 1
    Also after doing the steps that @JoaoHornburg mentioned I had to push origin master on the first push to create a master branch on the new bare repo. After than git push worked fine.
    – Daniel
    May 10, 2013 at 15:46
58

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)
2
  • Yep, seems the best solution.
    – Profpatsch
    Mar 13, 2013 at 14:27
  • I don't think this solution existed in the released versions of git at the time I wrote my answer, but it definitely seems easier. :)
    – clee
    Oct 21, 2015 at 17:23
28

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

2
  • 2
    this comment should be top. the only one-liner that doesn't depend on git's internal config structure Aug 21, 2015 at 13:12
  • I agree, I think this is the best answer. It's simple and does what you need in one line.
    – imns
    Feb 8, 2016 at 16:11
26

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.

6
  • Well, as you said, it's a non-bare repo, I'm a little confused. What to do now ?
    – Ben Orozco
    Jun 10, 2010 at 3:48
  • Found stackoverflow.com/questions/1784506/…
    – Ben Orozco
    Jun 10, 2010 at 3:55
  • As above, all you need is the --bare option when cloning what is going to be an upstream repo. Jun 10, 2010 at 5:01
  • Well, you CAN push to non-bare repos - but you REALLY SHOULD NOT!
    – hurikhan77
    Jun 12, 2010 at 19:44
  • thanks for the advice. i thought it would be as easy as changing the config, just needed confirmation. Nov 23, 2012 at 7:16
4

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.

2

why not simply :

git remote remove origin

git remote add origin <Dreamhost-git-URL>

git push -u origin --all --tags
3
  • I had created an empty repository on github. On local setup, I had cloned from the repository, then added some files and pushed to the github repository. Then I created a fresh repository on gitlab, and imported code from the github repository. Now I want to change the remote repository reference of my local repository to this gitlab repository. I did git remote add origin <gitlab-URL> on my local repository. It did not not show any error (am I supposed to get some result? I did not get any success message either). But, now I am not able to see changes made in the gitlab repo on my local. Mar 17, 2016 at 8:14
  • I have tried all the suggestions but I don't have the tags in the new origin. How I have to do for moving the tags too? Dec 22, 2020 at 21:42
  • 1
    @StefanoBossi : git push --tags ?
    – gjambet
    Dec 24, 2020 at 9:00

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.