OOZOU
お問い合わせ
Back to TIL
shell

Diff a local file with remote version in Git

2020年10月13日

Easily run the below command and get a diff version from the remote

$ git diff origin/master -- [local-path]

Local and Remote Branches

When using Git, it’s important to know the difference between local and remote branches. A local branch is a branch that only exists on your machine and is not shared with other developers or the remote repository. A remote branch is a branch that exists on the remote repository and can be accessed by other developers or through the remote repository.

Local branches are used for personal development, testing and experimentation, remote branches are used for collaboration, sharing and deployment. When you create a local branch you can work on it independently without affecting the remote branch. But when you’re ready to share your changes with others you can push your local branch to the remote repository, creating a new remote branch or updating an existing one.

Fetching the latest changes

Before comparing local and remote branches you need to fetch the latest changes from the remote repository. This will make sure your local repository is up to date with the latest changes from the remote repository. To fetch the latest changes use the git fetch command. This command updates your local repository with the latest changes from the remote repository without merging them.

Using Git Diff to compare files

Git Diff is a great tool to compare files between local and remote branches. To compare files using Git Diff use the git diff command followed by the names of the branches you want to compare. For example to compare the files in the local branch main with the files in the remote branch origin/main use the command git diff main origin/main.

Git Diff will show you the differences between the two branches, it will highlight the changes made in the remote branch compared to the local branch. You can also use the --stat option to show a condensed version of the differences, showing the number of added, deleted and modified lines.

Best practices for comparing local and remote

When comparing local and remote branches you should follow best practices to get accurate and fast results. Here are some best practices to keep in mind:

  • Always fetch the latest changes from the remote repository before comparing local and remote branches.
  • Use Git Diff to compare files between local and remote branches.
  • Use the --stat option to show a condensed version of the differences.
  • Use the git log command to compare commit histories between local and remote branches.
  • Use the git status command to see the status of your local branch and the remote branch.

Advanced comparison techniques

In addition to Git Diff and Git Log there are advanced comparison techniques you can use to compare local and remote branches. Here are a few:

  • Use git difftool to compare files between local and remote branches using a graphical difftool.
  • Use git diff --name-only to list the modified files between local and remote branches.
  • Use git diff --word-diff to show the differences word by word.
  • Use git diff --ignore-space-change to ignore whitespace changes.

Now you have more tools to compare local and remote branches.

More on shell

shell2020年12月8日

Run incognito/private commands for Bash and Zsh

Simply put a space before the command and it won't be saved to ~/.bash\_history. E.g. qrencode -o out.png "Some secret text"

shell2020年10月22日

Upgrade postgres database with homebrew

To upgrade postgres you can run

shell2020年10月13日

Amazon AWS S3 CLI copy with set perms

Open term (or equivalent) and paste the following:

プロジェクトをお考えですか?

あなたが構築しているものについてお聞かせください。

会話を始めるhello@oozou.com
OOZOU Logo

バンコク · シンガポール · 香港

X
Facebook
Instagram
LinkedIn

サービス

  • ウェブ開発
  • AI・生成AIソリューション
  • モバイルアプリ開発
  • データ分析・エンジニアリング
  • UI/UXデザイン・プロダクトデザイン
  • デジタルトランスフォーメーション

会社情報

  • 会社概要
  • 採用情報
  • ブログ
  • ホワイトペーパー
  • 事例研究
  • Today I Learned
  • お問い合わせ

その他

  • 業界
  • 見積もりを取得
  • パートナーネットワーク
© 2026 OOZOU. All rights reserved.
プライバシーポリシー行動規範ABACポリシー