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.
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:
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:
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.
Then compare the ranges the other way around:
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.
You may see output such as:
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:
If no upstream is set, configure one when pushing or with --set-upstream-to.
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.
for outgoing-style local commits, and:
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 --onelineis the usual Git equivalent ofhg outgoing.' - '
git fetchfollowed bygit log HEAD..@{u} --onelineis the usual equivalent ofhg incoming.' - '
git status -sbgives a quick ahead-behind summary.' - '
git branch -vvhelps verify the upstream tracking branch.' - In Git, the concept is the same, but the workflow is expressed through commit-range comparisons rather than dedicated
incomingandoutgoingcommands.
Related reading
- What is the impact if delay kafka manual commit offset?
- what is the meaning of Distributed word in Distributed Version Control System like Git?
- What is the meaning of git reset --hard origin/master?
- What is the precise meaning of ours and theirs in git?
- What is the purpose of Android's merge tag in XML layouts?
- What is the shortest way to swap staged and unstaged changes in git?
- What is the Sign Off feature in Git for?
- What should be in my .gitignore for an Android Studio project?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseNo 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 courseInterview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.