# GIT migration

### <mark style="color:blue;">Step 0</mark>: Update the GitHub migration sheet with the following details - ETA Dec 15th, 2022

1. Make sure you have signed-up to <https://github.com/kaleyra>, if not reach out to IT
2. Update the following details in the [sheet](https://docs.google.com/spreadsheets/d/1lLXBArZCnBBbo3W2voj92bERux5HBVplmlO8M2Xn73g/edit#gid=1039076166) here
   * BitBucket Repo name, URL
   * CodeOwner, Team-name, GitHub IDs of the developers who need write access

### <mark style="color:blue;">Step 1:</mark> DevOps will Create the repository on Github - ETA Dec 16th, 2022

1. Based on the Step 0 Information DevOps will ensure the repos are present in GitHub, so that the dev can push the code changes from their local machine as per step 2
2. To create the GitHub team with the specific Devs and Branch Protection rules.&#x20;

### <mark style="color:blue;">Step 2</mark> : Moving all code and content from bitbucket

1. Each dev owners of the repos, Pull the latest code from BitBucket into your local machine either by git clone or git pull and add the "<mark style="color:purple;">github</mark>" as an alternate remote.
   1. <mark style="color:orange;">**Option 1**</mark>: If you do not have a local repo, here the vector repo is taken as example, you          replace your respective repo name .

      ```

      git clone git@bitbucket.org:kaleyra/vector.git && cd vector && git remote add github git@github.com:kaleyra/vector.git 
      ```
   2. <mark style="color:orange;">**Option 2**</mark><mark style="color:orange;">:</mark> You already have a BitBucket repo local copy&#x20;

      ```
      cd vector 

      git pull && git remote add github git@github.com:kaleyra/vector.git
      ```

2\. Now let's do little cleanup on the existing branches and standardise it

1. Ensure that we have the standard branch names as. "master", "stage", "develop", all small cases. Incase in the existing BB repo, the branch names are either of the following, "Develop", QA, etc. You can map it correctly using the any of the (or) all of the following commands depending on the situation.
   * ```
     git checkout -b develop --track origin/Develop

     git checkout -b stage --track origin/QA 
     ```
2. Now, as a next step, lets cleanup the existing unwanted repos before pushing to GitHub, the following command retains only "master", "stage" and "develop", all the remaining branches will be restricted from pushing to github.
   * ```
     git branch -r | grep origin/ | grep -v 'master$' 'develop$' 'stage$' | grep -v HEAD| cut -d/ -f2 | while read line; do git push github :$line; done;
     ```

     Note: if the removal of the branches are taking too much time, you can abort it by Ctl+C or Ctl+cmd

3\. All done, let's push required branches and tags to GitHub Repository using below commands

```
git push --mirror github

git push --tags github
```

### <mark style="color:blue;">Step 3</mark> : Add the CODEOWNERS

1. Once the code is migrated to GitHub, you need to create a file at the root of the repo named "CODEOWERS", you may have to copy this file across required branches with either same or different reviewers. Below is the sample file.

```
$ # Lines starting with '#' are comments.
# Each line is a file pattern followed by one or more owners.

# More details are here: https://help.github.com/articles/about-codeowners/

# The '*' pattern is global owners.

# Order is important. The last matching pattern has the most precedence.
# The folders are ordered as follows:

# In each subsection folders are ordered first by depth, then alphabetically.
# This should make it easy to add new rules without breaking existing ones.

# Global rule:
*           @kaleyra/core

# Global rule, multiple teams:
*           @kaleyra/core, @kaleyra/core-sre

# Node# samples: Adding multiple individaul code reviewers
/bills/**  @Vijay, @peppe

# Specific Files
/bills/*yaml @Balu

# WPF folders:
/wpf/**   @adegeo

# Windows forms areas:
/windowsforms/** @adegeo @dotnet/dotnet-winforms
```

### <mark style="color:blue;">Step 4</mark> : Update the existing jenkins git url

1. SREs to update the git urls of the jobs to github


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://devops.kaleyra.io/gitops/git-migration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
