Importing an existing repository into Stash

Martin Ehrnhoefer May 10, 2012

Hi,

I have my brand new Stash server installed, and now I am trying to migrate my Git repositories (which are currently hosted on some remote site). I already created a local copy using "git clone --mirror"(which includes all branches).

My question is:

What is the preferred way to import such a bare repository - including all branches and tags - to Stash?

My ideas so far:

- use a local script that pushes all branches and tags - one by one - to the Stash server

- got to the Stash "data/repositories" directory and execute a "git clone --mirror" there

Thanks!

Martin

8 answers

1 accepted

10 votes
Answer accepted
Semyon Vadishev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 1, 2012

One has to be very careful using

git clone --mirror

This command sets force update for all the references of remote origin:

[remote "origin"]
	url = ...
	fetch = +refs/*:refs/*
	mirror = true

As result one may accidentaly rewrite the whole history of mirrored repository just by running:

git fetch origin

That's why one should remove the remote right after the clone is completed:

git remote rm origin

So the whole sequence should be as follows:

git clone --mirror $ORIGINAL_URL
git remote rm origin
git remote add stash $STASH_URL
git push --all stash
git push --tags stash

Another important note: if you're importing Subversion repository into Stash with git-svn, I'd highly recommend you to use SVN Importer Plugin instead, here are the reasons:

  1. It doesn't use git-svn, git-svn is slow and terrible;
  2. It uses SubGit instead, SubGit is fast and awesome;
  3. SVN Importer Plugin uses Stash users to map SVN authors into Git committers;
  4. SVN Importer Plugin properly handles branches, tags, merge-tracking information, EOLs, MIME types, etc;

Hope that helps.

Sven [Dione Technology]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 26, 2014

On clone and remote rm orgin, do we still keep link to the origin one or the old and new report are strictly seperate ?

3 votes
Martin Gregory March 4, 2015

I'm astonished how convoluted it is to get set up to use Stash with an existing git repo.

Why on earth doesn't Stash handle this for us?    I should just have to tell stash where my existing repo is and it should take care of the rest!

 

3 votes
Jens Schumacher [Atlassian]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 10, 2012

Hi Martin,

You should be able to push all Branches and Tags to Stash by changing the origin (or adding Stash as another remote) and run "git push --all" and "git push --tags". Note that "all" includes all Branches, but not the Tags.

See the documentation for details: http://git-scm.com/docs/git-push

Cheers,
Jens

Martin Ehrnhoefer May 10, 2012

thx! i missed the "--all" option...

1 vote
Ellen Feaheny [AppFusions]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 24, 2012

For future reference, AppFusions just released a "Source Code Importer for Atlassian Stash" plugin to help reduce the headaches in this.

Initial release supports code from SVN SCM. More SCM support coming!

Questions - don't hesitate to let us know - happy to help!

Ellen

info@appfusions.com

GarethB June 24, 2015

That plugin doesn't seem to be available any more - the link points to a generic AppFusions page.

1 vote
Jens Schumacher [Atlassian]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 10, 2012

On another note... I would suggest to never edit the data directory manually.

0 votes
BenW October 10, 2012

Maybe you guys should update the docs then?

seb
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 11, 2012

Thanks Ben, I've done that now. Sorry for the oversight!

0 votes
AdamP October 9, 2012

When I follow those instructions, I get to the final step (the push --all) and get:

$ git push --all origin
error: --all and --mirror are incompatible

seb
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 9, 2012

If you clone a repository with --mirror, you cannot use --all. The mirror option will push all refs to origin.

0 votes
Jens Schumacher [Atlassian]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 23, 2012

Importing external projects into Stash is now documented:

https://confluence.atlassian.com/display/STASH/Importing+code+from+an+existing+project

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events