How to merge two different GIT repositories sitting on two different places
So recently in office i had to push the code that i was working with to my client's own code repository. My code base was on Gitlab and client had his own repo on BitBucket. Basically the same code base but on two different places. So how do i merge my code into client's repo ? i found this answer HERE on this great article.
But i will explain what i did step by step just to make it clear to you.
Let's assume that my requirement is to merge a repo called my-source into my-target. my-source is on Gitlab and my-target is on BitBucket.
Here are the steps.
1. Clone my-target on your trusty computer in a preferred folder.
2. Add the source ( the repo which you are trying to merge into your target ) as shown below to the local repo you cloned in step 1.
git remote add -f my-source https://git.myawesomecodebase.com/my-source.git
3. You're almost there , now merge your branches together. In the following example i'm merging a branch called develop into my target repo.
git merge my-source/develop --allow-unrelated-histories
Please note that you have to use --allow-unrelated-histories here otherwise you will get an error.
Ok that's it ! You are done ! Your code is now merged.
Bonus tip
Feel free to pass any merge parameters of your preference like no fast forward , no commit , strategies etc. An example of how i usually run the merge command is shown below.
git merge my-source/develop --no-commit --no-ff --strategy-option theirs --allow-unrelated-histories
Enjoy !
'
But i will explain what i did step by step just to make it clear to you.
Let's assume that my requirement is to merge a repo called my-source into my-target. my-source is on Gitlab and my-target is on BitBucket.
Here are the steps.
1. Clone my-target on your trusty computer in a preferred folder.
2. Add the source ( the repo which you are trying to merge into your target ) as shown below to the local repo you cloned in step 1.
git remote add -f my-source https://git.myawesomecodebase.com/my-source.git
3. You're almost there , now merge your branches together. In the following example i'm merging a branch called develop into my target repo.
git merge my-source/develop --allow-unrelated-histories
Please note that you have to use --allow-unrelated-histories here otherwise you will get an error.
Ok that's it ! You are done ! Your code is now merged.
Bonus tip
Feel free to pass any merge parameters of your preference like no fast forward , no commit , strategies etc. An example of how i usually run the merge command is shown below.
git merge my-source/develop --no-commit --no-ff --strategy-option theirs --allow-unrelated-histories
Enjoy !
'
Comments
Post a Comment