1

I have been developing 2 parts of a project separately, and I'd like to merge them. I did not push any of them to a remote server, but I want to.

2 local repos to merge :

  • software on Linux PC (SW)
  • microcontroller firmware on Windows PC (FW)

How do I end up with a single repository with this structure ?

project
|
+----fw
|
+----sw

And if possible, keep the history of SW and FW ?

This article explains a similar situation. But I wonder if I could do the same, setting up only one remote, like :

  1. push SW to remote from Linux
  2. clone SW from Windows into a new directory
  3. create a branch called merge-fw
  4. pull FW from local directory → what's the syntax for the repository argument in git-pull ???
  5. merge merge-fw into master

Thanks.

dpeng
  • 395
  • 2
  • 4
  • 17

1 Answers1

0

Let's assume the Windows repo shall become the master repo for a moment.

On the Linux repo

Ensure all your sources are located under a sw directory, if needed move files and git commit these changes. Create a new branch merge-to-windows:

    mkdir sw
    mv !(sw) sw # needs extglob set (shopt -s extglob)
    git add . && git commit -m "move all sources to sw"
    git checkout -b merge-to-windows

On the Windows repo

  1. Ensure all your sources are located under a fw directory, if needed move files and git commit these changes

  2. Add a new remote to the Windows repo pointing to your Linux repo

    git remote add linux <path to your linux machine>
    
  3. Fetch the current state of your Linux repo with

    git fetch linux
    
  4. Merge the merge-to-windows branch of your linux repo

    git merge linux/merge-to-windows
    
  5. Now your master branch on Windows holds the history of sw and fw. We can push this state back to the master branch on Linux

    git push linux master:master
    

Done

Community
  • 1
  • 1
eckes
  • 64,417
  • 29
  • 168
  • 201
  • Great, I worked ! Although a little off topic, this [related post](https://stackoverflow.com/questions/3596260/git-remote-add-with-other-ssh-port#3596272) on _git remote add_ syntax may help noobs like me. – dpeng Apr 14 '16 at 11:06