Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git doesn't show how many commits ahead of origin I am, and I want it to

Tags:

git

There are plenty of questions here about Git saying people are ahead of a remote branch by X commits, and they want it to stop.

I have the opposite problem. I want Git to tell me how many commits ahead I am, but it doesn't.

When I created my remote bare repository first, then cloned from it, this worked. In my current case I created the local repository first, then cloned it (bare) to the remote.

This set up my local repository as the remote for the bare repository. But I removed that, and manually added the remote repository reference to my local. Pushing works fine. But I don't see the "You are ahead by X commits" message. How can I get it?

like image 843
Ryan Lundy Avatar asked Mar 17 '11 15:03

Ryan Lundy


People also ask

How do I fix my branch is ahead of origin master by three commits?

There is nothing to fix. You simply have made 3 commits and haven't moved them to the remote branch yet. There are several options, depending on what you want to do: git push : move your changes to the remote (this might get rejected if there are already other changes on the remote)

What is commit ahead in git?

This means that one commit can find another—earlier—commit. As Think Like (a) Git notes, this is a bit like a railway train.

How can I see Unpushed commits?

We can view the unpushed git commits using the git command. It will display all the commits that are made locally but not pushed to the remote git repository.

What is git push?

The git push command is used to upload local repository content to a remote repository. Pushing is how you transfer commits from your local repository to a remote repo. It's the counterpart to git fetch , but whereas fetching imports commits to local branches, pushing exports commits to remote branches.


2 Answers

git branch --set-upstream local origin/remote

local and remote are the names of your local resp. remote branches.

In Git version 1.8 and later, it's even easier. Make sure you're on the local branch, and then:

git branch --set-upstream-to origin/remote

like image 187
Bombe Avatar answered Sep 23 '22 21:09

Bombe


I found that there's a way to make this behavior the default:

git config --global branch.autosetupmerge always 

Despite the name, this doesn't force you to always merge branches; you can still rebase if you want to.

It will ensure that any time you create a new branch, you'll automatically be able to see how many commits different it is from the branch it was created from.

like image 45
Ryan Lundy Avatar answered Sep 19 '22 21:09

Ryan Lundy