Space logo

Space

The intelligent code collaboration platform

Space is pivoting to SpaceCode, focused on Git hosting and code reviews. Learn more →

How-To's

Mirroring an External Git Repository in Space

Creating a new Git repository in Space is easy. You can create and initialize a new or empty repository and start pushing code, or migrate an existing Git repository from GitHub or BitBucket and make it available in Space, including all branches, tags and commits.

There’s an additional option: mirroring a repository. In this post, let’s have a closer look and see how you can mirror Git repositories in Space.

Why mirror a Git repository?

A mirrored Git repository in Space is an always-in-sync copy of another Git repository. Synchronization can be “pull-only”, when Space automatically pulls all commits (and tags & branches) from a remote. A bi-directional mirror can be set up as well, where changes pushed to Space are automatically pushed to the remote.

Mirror repository from external Git
When an “always-in-sync” mirror of a public repository is needed, Space can help. Having such a mirror may reduce latency while accessing the main repository. Git repository mirrors can be browsed and searched in Space, even if the original repository does not provide that functionality.
Repository mirroring can also help simplify user management. Teams can work with the repository that is hosted in Space, where authentication and access are handled. Space itself then propagates commits and other changes to the remote repository.
A mirrored repository can also help with migrating to Space. Instead of doing a big-bang migration where all developers have to update their Git remote immediately, they can push changes to both the original repository and Space. Both repositories will always be in sync, so there’s no rush to move developers and continuous integration servers over to a new repository URL at once.
At JetBrains, we have a few repositories (such as Kotlin) that we host in Space, and mirror on GitHub. Our developers typically commit code to Space, and external contributors use GitHub. Space keeps both repositories in sync.

Setting up a Git repository mirror

In any project, we can create a new Git repository. Mirroring is one of the options available when setting up the repository:
Setting up repository in Space to mirror a project from GitHub
After selecting Mirror a repository from another Git hosting, we’ll have to specify the remote URL and set up the behavior of our mirror:

  • Since we are mirroring, we want to check the remote repository for changes and bring them to Space. This can be done periodically and/or when a developer does a git fetch.
  • To propagate pushes from Space to the remote repository, enable Allow push to proxy.

Optionally, we can set a Git refs pattern (refspec) to filter out the branches we want to mirror. For example, we can set the refspec to +refs/heads/master to only mirror the master branch.
We’ll also have to set credentials to connect to the remote repository. If the remote is public, fetching can be done anonymously. For private repositories, as well as repositories we want to push to, we will need to set credentials – either a username/password combination or an SSH key.
After creating the mirrored repository in Space, an initial synchronization will happen to make sure all commits and branches (matching the refspec) are available in Space.

What’s next?

Once set up, we can start working with our mirrored git repository. We can pull changes from Space, commit code to our repository, and explore and review code. Developers committing to Space will see their changes in the remote, and those committing to the remote directly will see those changes in Space.
Give JetBrains Space EAP a try and let us know what you think!

image description