Moving a Git Repository

Every once in a while you might need to move a Git repository while preserving the history.


Here is how you can move or duplicate a Git repository from an initial repository to a new repository

git clone
git remote rm origin
git remote add origin
git push -u origin main


My friend Leila built a website for Fearless into Tech community. She shared the code of the website on her GitHub profile.

Since more members in the community wished to contribute to the website, we created an organization on GitHub. That way anyone in the community could create issues, write code and improve the website. We then needed to move the repository from Leila's personal GitHub profile to the new organization while preserving the commit history to reflect her contributions.

Here is how you can move a Git repository:


Clone the repository you want to move by running

git clone


Check remote repositories it is connected to by running

git remote -v

Output example showing a remote called origin which points to the original git repository.

origin (fetch)
origin (push)


Remove the remote called origin by running

git remote rm origin

Check that the list of remotes was empty by running git remote -v


Add a new remote and call it origin

git remote add origin


Push to the main branch of the new repository

git push -u origin main

Let me know if there is an easier way to do this :)

No Comments Yet