How to move your active branch from GitLab to GitHub?
Hello. We need a couple simple steps. We will use git remote and git rebase. We decided to move only active (in development / QA) branches. There is no need to move every branch since we don't need them anymore.
Prerequisite
You need to have github repo cloned locally on ~/dev/powr and the easiest way is to have
powr-cli installed:
- If you have fresh macOS with no
brew,nvm,wgetinstalled on your system then run:
git clone https://gitlab.com/powr/powr-cli.git ~/dev/cli && cd ~/dev/cli && make install
- if you already have
brew,nvm,wgetinstalled and updated to latest versions withbrew updatethen run:
git clone https://gitlab.com/powr/powr-cli.git ~/dev/cli && cd ~/dev/cli && make
Now that you ready to move your branch on GitHub repo please follow the steps below.
1. Goto your GitLab project directory and open terminal.
Or type this in the opened terminal window:
source ~/.zshrc; d powr
2. Copy the name of the branch you want to move
Then type in terminal
export NAME_OF_YOUR_BRANCH=<replace-me-w-name-of-ur-branch>
please replace <replace-me-w-name-of-ur-branch> (including brackets) with the one in your buffer.
- If you need fast solution then do first two steps and then just copy and paste this into your terminal:
git checkout ${NAME_OF_YOUR_BRANCH} \
&& git remote add github https://github.com/powrful/powr \
&& git push github ${NAME_OF_YOUR_BRANCH} \
&& cd ~/dev/powr/ \
&& git checkout main \
&& git pull \
&& git checkout ${NAME_OF_YOUR_BRANCH}
and only then proceed to step the last step #9.
- If you want understand what you are doing then ignore previous command and follow step by step.
3. Now checkout to the branch you want to move to GitHub.
git checkout ${NAME_OF_YOUR_BRANCH}
Just copy and paste this line in the opened terminal window.
4. Add new remote which will point at GitHub.
git remote add github https://github.com/powrful/powr
5. Make sure that remote has been added.
Simply run:
git remote -v
in your terminal. Output should look similar to this:
$> git remote -v
github https://github.com/powrful/powr.git (fetch)
github https://github.com/powrful/powr.git (push)
origin https://gitlab.com/powr/powr.git (fetch)
origin https://gitlab.com/powr/powr.git (push)
6. Push your branch to github.
git push github ${NAME_OF_YOUR_BRANCH}
If successful, you should see something like this:
To github.com:powrful/powr.git
[new branch] <branchName> -> <branchName>
7. Make sure that the main branch on github is up to date!
To do that run this:
cd ~/dev/powr/ && git checkout main && git pull
Now after we uploaded a branch to GitHub and pulled last commits we need to rebase it to GitHub's main branch.
8. Checkout to GitHub's newly added branch
cd ~/dev/powr/ && git checkout ${NAME_OF_YOUR_BRANCH}
9. Now just rebase it to main with:
git rebase main
You could have some merge conflicts during this stage — resolve them all and you're all set,
your branch is moved to github and rebased with it's main branch, you have working powr-cli and
your github repo is located at ~/dev/powr/. Please do not merge your branches to main or
staging branches on github, until notify from payback that it's safe to merge your branches.
Now you could run d powr to go to powr github repo in CLI and d cli to go to powr-cli.