Amelio Vazquez-Reina
Amelio Vazquez-Reina

Reputation: 96274

Visualizing and understanding a fast-forward in git

I just fetched from origin and git status reports:

Your branch is behind origin/ by 13 commits, and can be fast-forwarded

Strictly speaking, what does this exactly mean? Does it mean:

  1. that HEAD is behind the corresponding remote-tracking-branch (origin/<branch_name>).

  2. or that <branch_name> is behind the corresponding remote-tracking-branch (origin/<branch_name>)?

What if I am on a detached HEAD? (i.e. if my HEAD and <branch_name> don't point to the same commit).

Is there a way to visualize these pointers (HEAD, <branch_name> and origin/<branch_name> on a graph? I have tried with git log --graph, but I think I only see the different commits and they merge overtime.

Upvotes: 0

Views: 820

Answers (2)

Peter Lundgren
Peter Lundgren

Reputation: 9197

Let's look at an example. This repository has a remote called origin with a branch called master. I also have a branch called master which I currently have checked out.

% git log --decorate --graph --pretty=oneline --abbrev-commit --all
* 072a57a (origin/master, origin/HEAD) C
* 87011c4 B
* d3c4a48 (HEAD, master) A

When I run git status it tells me that my branch master is behind origin/master by two commits.

% git status
# On branch master
# Your branch is behind 'origin/master' by 2 commits, and can be fast-forwarded.
#
nothing to commit (working directory clean)

Upvotes: 3

CB Bailey
CB Bailey

Reputation: 791869

"Your branch" means the branch that your are on so HEAD is pointing at <branch_name> and 1 and 2 mean the same thing. (git status only reports about the status of the branch you are on, not all local branches.)

The message means that your branch is a pointing to a commit that is a direct ancestor of the remote branch head, so it points to a commit somewhere on the network of parent commits of the head of the remote branch. It's nothing more complicated than this.

If you received the message while you were on a detached head then you should log a bug - it shouldn't happen.

Note that your branch name doesn't have to match the branch name on the remote - the message will tell you that <alt-branch-name> is behind origin/<branch-name> provided that <alt-branch-name> is tracking origin/<branch-name>.

Upvotes: 1

Related Questions