Looking for a JavaEE Architect or Potential Tech Co-Founder?
Please don't hesitate to contact me.

GIT: How to have 2 local branch pushing to 2 different remote repositories so that you can merge code

This tutorial will explain how to create 2 local branches with the same code base, each linked to different repository. The purpose is that you can share code between repositories. For example in a multi-module project, it's possible that 1 project will have different implementation depending on the client.

Assumptions:
1.) You have a github account.
2.) You already have 1 project pushed in your account.
3.) You have another empty github project.

Steps:
1.) Add the empty remote repository, name it clone.
2.) Create a local branch name clone -> select checkout new branch.
3.) Push to upstream so that the local branch will be added to the original repository.
4.) Configure clone branch set remote=clone.
5.) Double click clone local branch.
6.) Push to upstream to commit the changes to the empty repository. Go to github and check if the project is properly pushed.
7.) You can now switch between local branch and push to the necessary remote branch.
*Note: The 2 local branch can now be merge

What if you want to delete the remote repository and the clone branch in your original project?
1.) Delete local clone branch, first you mush double click the master branch so the clone branch is not active.
2.) In command prompt go to the first repository's directory and execute: git push origin --delete clone
3.) Delete remote branch
GIT: How to have 2 local branch pushing to 2 different remote repositories so that you can merge code GIT: How to have 2 local branch pushing to 2 different remote repositories so that you can merge code Reviewed by Edward Legaspi on Thursday, January 30, 2014 Rating: 5

No comments:

Powered by Blogger.