6

GitHub screenshot:

enter image description here

There's only one branch, master. git status says there's nothing to commit. How is that branch zero commits ahead and behind itself?

I see this on GitHub forks. Is it just a confusing status message?

Dan Dascalescu
  • 143,271
  • 52
  • 317
  • 404
  • 1
    I'd guess that this is just a bug. Your master seems to be actually 5 commits ahead of the master of the repository you forked from. (looking at the compare link). And a branch (being only a pointer to a particular commit) will always be 0 commits ahead and behind itself (as it's pointing to the same commit as itself). Usually ahead/behind are for comparing corresponding branches in different repositories (e.g. origin vs. local), or possibly different branches in the same repository. – Charlie Nov 18 '13 at 20:03
  • @Charlie, that's the answer and worth upvotes if you post it as such ;) – Nevik Rehnel Nov 18 '13 at 20:34

1 Answers1

5

This is not a bug.

Once you fork a repo, each of your branch is compared to the branch which is common between the fork and the original repo.
That gives you a clear indication about you can or not make a pull request.

In this instance, your branch is master, which is means it is compared with itself, since master is also in the original repo.
Hence the "0 commit ahead and 0 commit behind" (with itself) message.

If you had done a commit of your own on, as I mention in "couple of tips on pull request", on a dedicated branch made from master, then your branch would have been a commit ahead of master.
You could then have made a pull request, from the owner of the first repo to consider.

fork

In any case, the purpose of that message is to remind you that the main goal of a fork is to collaborate and contribute back:

  • if your dedicated branch is behind, you want to rebase it against origin/branch (which you are supposed to keep in sync with the original repo, in other words, you are not supposed to work directly on master) in order to make sure your own work is compatible with the latest commits of the first repo,
  • if your branch is ahead, you could consider making a pull request and giving back.
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I think you're correct about how the mechanics should work, however in this particular case though, wouldn't: https://github.com/tmeasday/meteor-crypto-base/ be the original repo (the one that is forked from)? Since that repo does not contain afbba9f, the difference between the original:master and fork:master would not be 0/0 as the message indicates? (and still indicates despite now being further ahead of the original master?) – Charlie Nov 18 '13 at 22:43
  • @Charlie Thank you for the comment. Turns out, I wasn't quite correct about the *exact* mechanics. I have fixed the answer. – VonC Nov 19 '13 at 06:23
  • @VonC - 348k?! *gasp* – Dan Dascalescu Nov 20 '13 at 05:41
  • @DanDascalescu this (348k) is just a meaningless number. What matters is if my answer helped you understand that "ahead/behind" message: it helps reinforce the notion that you should always work on dedicated branch in a fork (at least one where you intend to contribute back). "Dedicated branch" means "a branch which doesn't exist in the original repo". – VonC Nov 20 '13 at 13:40