To add existing Git repository into a new remote Git server:
- perform a full local clone of the repository.
- If you already have the repo locally, update any branches you want to move to the new remote.
- Then, if you want to include all branches from the current remote run the command: git fetch --all
- Add the nw git remote with the command: git remote add origin [Git remote URL]
- This will add a remote repository with the friendly name of 'origin',
- If you no longer want to use the old remote repository / provider run the command git remote rm origin [assuming your remote is called origin - if not replace "origin" with the name of your remote]
- To send your source code to the new remote, run: git push origin --all. This will push all branches you have locally into the new repository.
- Note that you can call the remote whatever you want, and you can also have multiple remotes. For example, if you are keeping your existing remote, and it is called "origin", you can instead run the command git remote add gitlab [gitlab Git URL]
An alternative approach for when you want to move all code, branches, and tags on the remote:
- Clone the original repository with the
--mirror
option git clone --mirror <old_repo_url> - This creates a bare clone of the repository, including all branches, tags, and other metadata. A bare repository does not have a working directory. This is suitable for storing the central copy of your project for migration or analytical purposes only.
- Navigate to the cloned repository:
cd <old_repo_name>.git
- Add the new remote:
git remote add new_origin <new_repo_url>
(replace <new_repo_url> with the URL of your new remote repository.) - Push all branches and tags to the new remote:
git push new_origin --mirror