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?

Adam Dymitruk
  • 124,556
  • 26
  • 146
  • 141
Ben Orozco
  • 4,361
  • 4
  • 33
  • 49

6 Answers6

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.

clee
  • 10,943
  • 6
  • 36
  • 28
  • 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. – Jörg W Mittag Jun 10 '10 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 '10 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. – Daniel Luna Jul 12 '11 at 21:41
  • 5
    I had to run following commands: `git config branch.master.remote origin` `git config branch.master.merge refs/heads/master` – JoaoHornburg Feb 15 '12 at 18:29
  • @DanielLuna thanks for your comment, I added this to the answer. – Thomas Sep 06 '12 at 08:56
  • 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 '13 at 15:46
  • Easier way is: `git remote set-url origin ` – Craigo Sep 01 '22 at 04:44
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)
Octavi Fornés
  • 599
  • 5
  • 3
28

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

slashingweapon
  • 11,007
  • 4
  • 31
  • 50
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.

user229044
  • 232,980
  • 40
  • 330
  • 338
Adam Dymitruk
  • 124,556
  • 26
  • 146
  • 141
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.

Yann Ramin
  • 32,895
  • 3
  • 59
  • 82
2

why not simply :

git remote remove origin

git remote add origin <Dreamhost-git-URL>

git push -u origin --all --tags
gjambet
  • 369
  • 5
  • 13
  • 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 ` 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. – Sandeepan Nath Mar 17 '16 at 08: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? – Stefano Bossi Dec 22 '20 at 21:42
  • 1
    @StefanoBossi : git push --tags ? – gjambet Dec 24 '20 at 09:00