Git
Mercurial
Version Control
hg outgoing
hg incoming

What is the git equivalent of of hg outgoing hg out or hg incoming hg in?

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

Git does not have a single built-in command that exactly matches Mercurial's hg outgoing and hg incoming, but the underlying information is easy to get. In Git, you normally compare your current branch with its upstream tracking branch. For outgoing changes, look at commits you have locally that the upstream does not. For incoming changes, fetch first and then look at commits the upstream has that your local branch does not.

The Git Mental Model

In Mercurial, hg outgoing and hg incoming are explicit commands. In Git, the equivalent idea is expressed through commit-range comparisons between:

  • 'HEAD, your current local branch tip'
  • '@{u}, the upstream tracking branch for the current branch'

That gives you a very direct mapping once an upstream is configured.

Equivalent of hg outgoing

To see commits that are local but not yet in the upstream branch:

bash
git log @{u}..HEAD --oneline

This means: show commits reachable from HEAD that are not reachable from the upstream branch.

That is the practical Git equivalent of "what would I push if I pushed now."

You can also use:

bash
git cherry -v

This is often useful when you want a push-oriented summary rather than a full log.

Equivalent of hg incoming

To see what exists in the remote branch but not in your current local branch, first update your remote-tracking refs.

bash
git fetch

Then compare the ranges the other way around:

bash
git log HEAD..@{u} --oneline

This means: show commits reachable from the upstream branch that are not reachable from your current branch.

That is the Git answer to "what would I get if I pulled or rebased now."

Use git status -sb for a Quick Summary

If you only need a fast ahead-behind summary rather than commit details, git status -sb is often enough.

bash
git status -sb

You may see output such as:

text
## main...origin/main [ahead 2, behind 1]

This does not list the commits, but it quickly tells you whether there is outgoing or incoming work.

Upstream Branch Requirement

These commands depend on your branch having an upstream configured. You can check that with:

bash
git branch -vv

If no upstream is set, configure one when pushing or with --set-upstream-to.

bash
git push -u origin main

Without an upstream, @{u} has no meaning for the current branch.

Compare Arbitrary Branches Explicitly

If you do not want to rely on the current branch's upstream, compare explicit refs.

bash
git log origin/main..main --oneline

for outgoing-style local commits, and:

bash
git log main..origin/main --oneline

for incoming-style remote commits.

This is useful in scripts or when examining branches other than the one currently checked out.

Common Pitfalls

The most common mistake is checking incoming commits without running git fetch first. Your remote-tracking branch may be stale, so the comparison is outdated.

Another issue is assuming Git has one direct drop-in replacement command. It usually expresses the same information through range comparisons instead.

Developers also sometimes forget to configure an upstream branch, which makes @{u} unusable.

Finally, remember that git pull changes your local branch, while git log HEAD..@{u} is only an inspection step. Use inspection first when you want Mercurial-like visibility.

Summary

  • 'git log @{u}..HEAD --oneline is the usual Git equivalent of hg outgoing.'
  • 'git fetch followed by git log HEAD..@{u} --oneline is the usual equivalent of hg incoming.'
  • 'git status -sb gives a quick ahead-behind summary.'
  • 'git branch -vv helps verify the upstream tracking branch.'
  • In Git, the concept is the same, but the workflow is expressed through commit-range comparisons rather than dedicated incoming and outgoing commands.

Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Basis Lab
No course covers this one yet

Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.

Build my course
Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions