Question

We are moving our repositories from Bitbucket to our local environment in Stash. I am able to import the latest version of our repositories but not the details of previous commits and versions.

Can you please guide me what I should do to import our repositories with all branches, commits and version details?

This is how we are importing our repositories:

  1. Create a folder on local, using Tortise Git, clone it.
  2. Open Git Bash, go to this folder(directoary) by changing path using CD command
  3. Run the following commands: git init

    git add --all
    
    git commit -m "Initial Commit"  
    
    git remote add origin http://User@localhost:7990/scm/PROJECT/repo.git
    git push -u origin master
    

As I'm new to Git, these may not be the correct way to do it.

Was it helpful?

Solution

You need to:

  • clone the Bitbucket repo
  • create a local branch for all Bitbucket branches
  • push everything to Stash.

That would means:

git clone -o bitbucket https://bitbucket.org/username/reponame
cd reponame
remote=bitbucket ; for brname in `git branch -r | grep $remote | grep -v master | grep -v HEAD | awk '{gsub(/[^\/]+\//,"",$1); print $1}'`; do git branch --set-upstream-to $brname  $remote/$brname ; done
git remote add origin http://User@localhost:7990/scm/PROJECT/repo.git
git push --all
git push --tags

Couple of notes:

  • I have named the remote for the Bitbucket repo 'bitbucket', instead of the default 'origin'.
    That is because you will end up working with your Stash repo by default.
    That is why I reserved the remote name "origin" for said Stash repo.

  • Making a local branch for every bitbucket branches is described here: "Track all remote git branches as local branches".

  • I wouldn't recommend working in that local repo (which is tracking all Bitbucket branches).
    I would rather cloned the newly filled Stash repo elsewhere, and work from there.

OTHER TIPS

To import the project files, commit history etc, you can do something like:

git clone --bare git@bitbucket.org:/login/myrepo.git
cd myrepo.git
git push --mirror git@stash.acme.com:/project/myrepo.git
cd ..
rm -rf myrepo.git
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top