0

I'm going to explain how to fetch files from one repo to another and manually merge files one by one using git.

The solution I propose is based on a couple of other posts you can find here and here.

You may also find these posts helpful:

git -p options

list files for a git commit

Hope this helps someone saving some time.

Community
  • 1
  • 1
mstroger
  • 1
  • 1

1 Answers1

0

1- Go to the folder containing your code from branch X of repo R1

2- Add repo R2 as upstream by running:

git remote add upstream

3- Fetch (do not pull) branch Y of repo R2:

git fetch upstream Y

note: if you have same branch names (in this case "Y") in R1 and R2 git will be confused at this stage and you have to disambiguate the branch name for git to proceed.

4- If you don't want to mistakenly push changes to upstream use a dummy URL as pushurl:

git config remote.upstream.pushurl "SOME RANDOM TEXT"

5- Figure out what files have changed in last commit in Y branch of R2 by

running the following command:

git rev-parse HEAD

git diff-tree --no-commit-id --name-only -r

note: you can run the above commands by either going to the folder containing branch Y of R2 or by checking out Y from R2 in the same folder

6- For merging changed files run:

git checkout -p upstream/Y PATH/TO/CHANGED/FILE/FILENAME you can choose "a" to stash all local changes and merging changes from upstream

7- For adding new files just run (do not use -p param): git checkout upstream/Y PATH/TO/CHANGED/FILE/FILENAME

Hope this helps.

mstroger
  • 1
  • 1