DEV Community

Santiago Zarate
Santiago Zarate

Posted on • Originally published at foursixnine.io on

Merge two git repositories

I just followed this medium post, but long story short:

Check out the origin/master branch and make sure my local master, is equal to origin, then push it to my fork (I seldomly do git pull on master).

git fetch origin
 git checkout master
 git reset --hard origin/master
 git push foursixnine
Enter fullscreen mode Exit fullscreen mode

I needed to add the remote that belongs to a complete different repository:

git remote add acarvajal gitlab@myhost:acarvajal/openqa-monitoring.git
 git fetch acarvajal
 git checkout -b merge-monitoring
 git merge acarvajal/master --allow-unrelated-histories
Enter fullscreen mode Exit fullscreen mode

Tadam! my changes are there!

Since I want everything inside a specific directory:

mkdir openqa/monitoring
 git mv ${allmyfiles} openqa/monitoring/
Enter fullscreen mode Exit fullscreen mode

Since the unrelated repository had a README.md file, I need to make sure that both of them make it into the cut, the one from my original repo, and the other from the new unrelated repo:

Following command means: checkout README.md from acarvajal/master.

git checkout acarvajal/master -- README.md
 git mv README.md openqa/monitoring/
Enter fullscreen mode Exit fullscreen mode

Following command means: checkout README.md from origin/master.

git checkout origin/master -- README.md
Enter fullscreen mode Exit fullscreen mode

Commit changes, push to my fork and open pull request :)

git commit
 git push foursixnine
Enter fullscreen mode Exit fullscreen mode

Top comments (0)