Question

I have merged a branch in to master and now I can see that in my git log

Some time has passed and now I want to know whether I previously also pushed master (with that commit) to the remote. How can I tell if it has been pushed?

I can think of a few workaround such as recloning the repository elsewhere, or resetting and checking and then re-merging but I feel that there's probably a somewhat simpler answer.

fyi this is different from How can I know in git if a branch has been already merged into master? as I know it has been merged, just don't know about the remote push.

Was it helpful?

Solution

Do

> git status

If the output is

# On branch master
nothing to commit, working directory clean

Then you have pushed the current commit.

If the output instead begins with

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#   (use "git push" to publish your local commits)

Then you have a local commit that has not yet been pushed. You see this because the remote branch, origin/master, points to the commit that was last pushed to origin. However, your branch is ahead of 'origin/master', meaning that you have a local commit that has been created after the last pushed commit.

If the commit you are interested in is not the latest, then you can do

> git log --decorate --oneline

to find out if the commit in question is before or after the commit pointed to by origin/master.
If the commit is after (higher up in the log than) origin/master, then it has not been pushed.

OTHER TIPS

If you have made multiple commits and not sure which one of them have been pushed to remote, try this:

git log origin/<remote-branch>..<local-branch>

Example:

git log origin/master..master

This would list out all commits in your local branch that have not been pushed to the remote branch mentioned.

A solution to do it programmatically:

git merge-base --is-ancestor HEAD @{u}

You may also want to check if your local directory is clean, e.g. there are no uncommitted file changes:

test -z "$(git status --porcelain)"

I suggest you run this:

$ git fetch --all
Fetching origin
Fetching upstream

This will fetch the latest data from all remotes.

Then you run:

$ git branch -v
  master       ef762af [ahead 3] added attach methods
* testing      4634e21 added -p flag
  upstream     1234567 [ahead 1, behind 7] updated README.md

This will show which branches you're ahead or behind on.

I posted this because none of the other answers mention fetching the remote data, that step is crucial.

you can use git log --graph --all --decorate, it will show where each ref is located (HEAD, master, origin/master etc.)

Try this. git branch -r --contains <sha1>

For a commit in my repository I can see it exists on the remote develop branch

git branch  -r --contains 7914e54ea7e30c7f446e791df66bd3a5805c978a
origin/develop
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top