Git - Get the difference between branches of two repositories

2.9k views Asked by At

How can we get the list of files differences between two branches residing in two separate repositories

Scenario: Suppose we have 2 repositories 'A' & 'B', B was created from A since A is the base repo. Now the development work has been taking place since long on both this repositories 'A' with branch 'support/v1' and 'B' with branch 'master'. I want to find and check which files are missing with 'B'. In short need an list of files difference between branches of this two repo.

repo  branches
A   => support/v1
B   => master

Need help to find the list of files using git

3

There are 3 answers

0
knittl On BEST ANSWER

Add both repos as a remote in your local repository and then run diff like you would for any other branches:

git clone pathorurl/to/A.git
cd A
git remote add B pathorurl/to/B.git
git fetch --all
git diff origin/support/v1 B/master

This will work for any two repositories, because git diff only looks at tree objects and is not interested in commit history.

0
eftshift0 On

What you need to do is have a 3rd repo that can see them both as remotes... or take one of them and add the other as a remote. Once you fetch the remote (or remotes, if having a 3rd repo with the 2 remotes), you should be able to see differences between whatever branches.

So... using the third repo approach:

git clone A some-directory
cd some-directory
# this repo has repo A as _origin_
git remote add repoB url-to-b
git fetch repoB
# now you can take branches and compare them (among many other things you can do)
git diff origin/support/v1 repoB/master
1
RMNull On

If git history was retained, you can try git diff as other answers suggest. If there was no git history, and was a separate commit, then you may try tools like Win Merge to compare the folders/files line by line. Also, some IDE's like IntelliJ Idea support this.