• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
Clean Programmer

Clean Programmer

Programming & DevOps Resources

  • Home
  • About
  • Contact

Automate git reposotory migration from local git server to bitbucket – Part 1

May 19, 2018 Monzurul Haque Shimul

In our organization, we have been using Git as our version control system. And we were using it in local server. Everything was running fine. Recently we planned to move from local server to bitbucket. The reasons behind this move are:

  1. We have added slack as our team collaboration tool and we wanted to use webhook to get notified in slack channels about repo changes.
  1. We have hired people from abroad, and sometimes colleagues needed to work from home. They couldn’t connect to local network to push to Git without vpn.
  1. Bitbucket offers unlimited number of repositories compared to github.

We started to use bitbucket for our new projects and planned to migrate all the repositories from local server to bitbucket. The following tasks are described in bitbucket documentation to import an existing Git project into Bitbucket Server.

  1. Check out the repository from your existing Git host. Use the –bare parameter:
    git clone --bare https://username@bitbucket.org/exampleuser/old-repository.git
  2. Log into Bitbucket Server and create a new repository (we’ve called it repo.git in this example).
  3. Locate the clone URL in the nav panel on the left (for example: https://username@your.bitbucket.domain:7999 /yourproject/repo.git).
  4. Add Bitbucket Server as another remote in your local repository:
    cd old-repository
    git remote add bitbucket https://username@your.bitbucket.domain:7999/yourproject/repo.git
  5. Push all branches and tags to the new repository in Bitbucket Server:
    git push --all bitbucket
    git push --tags bitbucket
  6. Remove your temporary local repository:
    cd ..
    rm -rf old-repository

We have a number of repositories to move to bitbucket and we realized it would take a lot of efforts and work hours to do this manually one by one. So we planned to automate the process and we came up with a bash script. We grabbed a list of all our existing repositories in a text file repo.txt containing one repository name per line. repo.txt is the input parameter for the bash script.

As you can see the script is reading the repo.txt file on line at a time, cloning the repo from local git server, creating new repository in Bitbucket using bitbucket-api, and pushing the code to newly created Bitbucket repo and finally remove the local repo from the machine where it is running. git clone --bare and git push --mirror commands are important as they ensure that all tags and branches are migrated over to Bitbucket.

Finally we were able to do the whole migration with this little script with no real manual effort and saving a lot of times. In the next post I will share the post-migration procedure for all the developers needed to do to point their copy of repositories to Bitbucket.

I hope this guide will be useful to you if you decide to migrate to Bitbucket. Check the second part of this migration guide here: Automate git reposotory migration from local git server to bitbucket – Part 2

Related Posts

Git Alias: Make your Git experience simpler, easier, faster and clean
Username and Password with Special Characters for Curl
Username and Password with Special Characters for Curl
Git Reference Guide For Clean Programmers

Categories: Git Tags: bash, bitbucket, git

Primary Sidebar

Categories

  • Apache Kafka
  • Druid
  • Git
  • Java
  • Java EE
  • Redis
  • Spring
  • Uncategorized
  • Weblogic
  • Wildfly

Featured Posts

A Quick Introduction to Redis HyperLogLog

Setting Up A Horizontally Scalable, Fault-Tolerant Druid Cluster

Adding 3rd Party Jar to a Maven Project

Loading data into Druid from TSV file

Deploy applications to a remote WildFly server using curl

Most frequently used commands for managing Kafka Topic

Footer

Monzurul Haque Shimul

I’m a full-stack software engineer with 10 years of experience in design and development of large scaled Enterprise Software Systems built on Java and Java EE related tools and technologies. I’m also a contributor on GitHub, Stack Overflow, DZone. My core expertise lies in building JVM-based, scalable, reactive, data-driven applications.

Follow

  • Email
  • GitHub
  • LinkedIn
  • Twitter

© 2019 CLEAN PROGRAMMER

  • Home
  • Archive
  • About
  • Contact
  • Privacy Policy
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.OKNoRead more
Revoke Cookies