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.