Dennis Hackethal
Dennis Hackethal

Reputation: 14275

Move git repository to another github user

There are many answers on Google that point in the same direction, but when it comes to version control I don't want to try anything and then mess up my repository.

I have set up a repository on GitHub and would like to move it to another user, so that I can close the repository. He would then invite me to the repo once it belongs to his account. I guess this is quite a common use case for working with clients - once you finished the project, you hand it over to them.

Now, assuming this is possible, how would I change my local Git settings in the project so that I am now pushing to/pulling from the new location? And, by moving the repo, would I lose the commit history?

Upvotes: 34

Views: 40527

Answers (5)

EnGlamdring
EnGlamdring

Reputation: 121

This can also be done directly with the desktop version of GitHub on a PC without installing CLI.

As stated above by @citruspi if you edit the config file you're doing what this command does for you manually.

git remote set-url origin git://new.url.here

Does for you if you have CLI.

https://stackoverflow.com/a/14132101/3099982

or edit the .git/config file.

Steps below...

  1. Create /newRepo in Github or Github Desktop.
  2. Clone that /newRepo to your local machine (if you didn't create it in Github Desktop).
  3. Clone the repo you want to clone onto your local machine as well /wantToCloneRepo.
  4. Delete the .git folder in /newRepo.
  5. Copy the files from /wantToCloneRepo to the local folder /newRepo
  6. Edit the file /newRepo/.git/config where the remote "origin" URL should now equal the new destination on Github. IE... https://github.com/DataAutomation/newRepo.git
  7. Look up where is used to say fetch origin and it will say Push.
  8. Push and it will preserve your commit history and you'll have a new repo without installing CLI.

Upvotes: 2

xero
xero

Reputation: 4319

Any of the following will work:

  • Just transfer ownership of the repo to another user and have them add you as a collaborator.

  • If someone forks your repo, then you delete the original, their fork is still there, unless it's a private repository. they can then add you as a collaborator on their fork repo.

  • Another user can simply clone your repo (commits intact), create a new repo on GitHub, add the new repo's remote info, and push your repo up to their new one. (Then, they can add you as a collaborator.)

Upvotes: 30

the.malkolm
the.malkolm

Reputation: 2421

Why don't you do it within github? Just transfer ownership to the new user. Go to Settings at Github.

Transfer Ownership: Transfer this repo to another user or to an organization where you have admin rights.

Upvotes: 6

citruspi
citruspi

Reputation: 6891

To answer the questions:

  1. You would not lose anything - not even commit history. The point of Git is that it is decentralized - everybody with a copy of the repository has everything. Just the new repo.

  2. It is easy to change the git settings to push to the new repository. You can either use

    git remote set-url origin git://new.url.here
    

    or edit the .git/config file.

I would say you should:

  1. Transfer ownership of the repository (or have the client fork it).
  2. Change your git config to push to the new repository
  3. You're done.

Upvotes: 14

matt
matt

Reputation: 534925

You would not lose anything. That's the point of git. Every copy of the project has a complete copy of the repo - you have it, github has it, anyone who forks it has it.

The configuration of the remote is just a line in the .git/config file:

    url = [email protected]:mattneub/Programming-iOS-Book-Examples.git

You can remove the old remote and create a new one, but the simplest thing is just to edit that line by hand.

There is no mystery here. The .git folder and your repository are directly open to your view.

Upvotes: 0

Related Questions