I have two branches: origin/A
and A
(locally).
Assuming one - and only one - has advanced by one commit, but I don't know which branch advanced, how do I tell which one has the extra commit?
I have two branches: origin/A
and A
(locally).
Assuming one - and only one - has advanced by one commit, but I don't know which branch advanced, how do I tell which one has the extra commit?
Use git fetch
to get the latest commits from the tip of your remote, then use git status
to tell whether or not your remote or local is ahead.
If origin/A
is ahead, then when you run git status
, you'll be told that your local A
branch is behind origin by a commit.
If your local A
is ahead, then when you run git status
, you'll be told that your local A
branch is ahead of origin by a commit.
git rev-list HEAD --count
will give you the number of commits on your current branch. Assuming you using github you can see the number of commits on the stop left of the repo.
If your goal is to do this as part of an automated bash script, you can use the git rev-parse
command. To see the commit hash of a given branch, use this command:
git rev-parse branchname
Or, to see the hash of the previous commit from a given branch, use this command:
git rev-parse branchname^
So, if you want to see which branch is ahead, you can run the following four commands and compare output:
git rev-parse A
git rev-parse origin/A^
git rev-parse A^
git rev-parse origin/A
If the output of the first and second commands match, then A
is the branch with one additional commit. If the output of the third and fourth commands match, then origin/A
is the branch with one additional commit.
If neither pair of commands has matching output, then you don't have one branch that is ahead of the other by exactly one commit.