Importing Git projects using the command line is suitable when your existing code is hosted on a private network.

Before you start, make sure you know:

  • Your user name.
  • The clone URL for the external repository, such as https://otherhost.com/user/repo.git or git://otherhost.org/user/repo.git (perhaps with a user@ in front of the otherhost.org domain name).

For purposes of demonstration, we'll use:

  • An external account named extuser
  • A personal user account named ghuser
  • A repository named repo.git
  1. Create a new repository on . You'll import your external Git repository to this new repository.
  2. On the command line, make a "bare" clone of the repository using the external clone URL. This creates a full copy of the data, but without a working directory for editing files, and ensures a clean, fresh export of all the old data.

    git clone --bare https://githost.org/extuser/repo.git
    # Makes a bare clone of the external repository in a local directory
    
  3. Push the locally cloned repository to using the "mirror" option, which ensures that all references, such as branches and tags, are copied to the imported repository.

    cd *repo.git*
    git push --mirror https:///ghuser/repo.git
    # Pushes the mirror to the new  repository
    
  4. Remove the temporary local repository.

    cd ..
    rm -rf repo.git