Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does it mean when it says a git step is "1 ahead"

I'm trying to learn git by playing around with it using SourceTree as as tool.

I added my local repository to a BitBucket repository and then made a couple of changes locally. I committed them, and then pushed them. I then logged onto BitBucket and manually changed a portion of the document (item "Added 4"). Then I went back to my local copy and changed it again and committed it. When I tried to push it, it told me I first had to pull and merge. So I did.

Then I pushed again. It worked.

Now, the master (the top one. Why are there two?) carries a caption saying 2 ahead. What does this mean exactly? What is it ahead of?

Git - SourceTree screenshot

UPDATE

git status gives me:

JustMe@IMRAY ~/Projects/BlaBlaUser/gitPractice (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
  (use "git push" to publish your local commits)

nothing to commit, working directory clean
like image 543
CodyBugstein Avatar asked Mar 12 '14 15:03

CodyBugstein


People also ask

What is git ahead and behind?

branch is X commits behind means that there are X new (unmerged) commits on the branch which is being tracked by your current branch. branch is X commits ahead analogously means that your branch has X new commits, which haven't been merged into the tracked branch yet.

How can a branch be ahead and behind Master?

A branch can be both ahead and behind at the same time if you have made changes to your branch, and someone else have made changes on the default branch that you have not merged into your branch yet.


2 Answers

Basically, you need to push to your remote branch again to get rid of the 2 ahead so to speak.

The master (the one on the top) is your local tracking branch, and origin/master is a remote tracking branch that records the status of the remote repository from your last push, pull, or fetch. origin refers to your remote repository and master is the current branch (also default) for that repository.

So in essence, it says that your branch (master) is ahead of the remote master branch (origin/master) by two commits, and that is why I say that you need to push again.

When you do a git status on your local, it should give you more clue about what is to be done.

like image 129
gravetii Avatar answered Nov 21 '22 11:11

gravetii


It means that you have local commits that have not yet been pushed to that remote.

For example:

* (master) Fix bar
* Fix foo
* (origin/master) Add bar
* Add foo

(newer commits are at the top)

Here you see that origin/master is two commits behind master.

You may use git push origin master to push your master branch to origin.

like image 33
Drew Noakes Avatar answered Nov 21 '22 11:11

Drew Noakes