I have a git repository clone locally on my machine that I’ve been working with for a few weeks and already merged my work once into the main repo(“origin”).
I can find my last merge(of course) in origin’s log but I’m wondering if there is the “right”(and automated) way to do it – to find out when was the last time this clone was pushed to origin?
I have a git repository clone locally on my machine that I’ve been working
Share
You need to find the common ancestor of your local branch and the origin branch. This can be done using
git merge-base:Which returns a commit hash.
Why it works: if you use a good git workflow, you will need to update your local branch with the latest remote changes (either with
mergeorrebase) before pushing. After this, your local branch will point to a commit containing your work and pushing to a remote just means to make the remote branch point to your commit.As a result, the remote repository will always contain the commit which was your head when you pushed.
However, this won’t work if someone else (or you, from another head) forces a push (
git push -f) and erases your commit. Forcing a push on a shared repository should be avoided except in some rare cases.