Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I show differences between local and remote files in Git?

Tags:

git

Since I am new to Git, I have some trouble getting started (Git version 2.12.3).

I created on a server a file (in GitLab) which I can clone to a local directory.

git clone [email protected]:/joe/myproject.git

All fine, and I have a local copy of the file. But when I change remote something to the file (from someone else or on the server), then I am not able to track or to see the changes on the local client, even if they are clearly visible on the master. Not with

git diff file1

or

git diff origin/master

or something else.

I have to fetch the file, merge it, and then I am able to see the newly edited content. Is it possible to observe and detect the new changes before fetching the new file?

like image 276
Coliban Avatar asked Oct 17 '17 08:10

Coliban


Video Answer


1 Answers

I would do it like this:

git fetch origin master

And then I would do:

git diff master origin/master

In a more simplified way, to see the difference in your local and remote repository, the syntax would be like this:

git diff <masterbranch> <remotebranch>

There is also git difftool command which shows the difference in a UI environment if you have installed one, I have rarely used this, so it's kind of an uncharted area for me. Have fun.

like image 81
Rahul Bhat Avatar answered Nov 15 '22 00:11

Rahul Bhat