A previous push disappears from your local branch when someone else overwrote it, when you rewrote history locally and pushed with --force, or when a branch was deleted and recreated. You can get it back from one of three places: the remote's reflog on a Git host like GitHub or GitLab, your own local reflog, or a recovery ref that git keeps for force-pushed commits. The condition that matters most is timing: unreachable commits on the server survive only until Git's garbage collection runs, so recover the commit hash before cleanup.

The query says "push back," which could mean two different things. One reading is recovering a commit or branch that a later push replaced (the force-push overwrite case). The other is undoing the push itself so the remote branch returns to its prior state (a revert or a force-reset). This article covers both, because the recovery procedure for the first is also the exact input you need for the second. The steps below assume you have normal push or admin access to the repository, though many recovery reads work even without it.

What "getting a push back" can mean in Git

Git has no built-in "undo push" button. A push is just a request to move a remote ref from one commit to another, so undoing one means moving that remote ref back and telling everyone else who fetched in the meantime. That's why the safe answer depends on whether anyone else pulled the bad push.

There are three distinct situations:

The remote branch was force-overwritten by someone (possibly you) and you want the old commits. This is recovery of lost objects. You pushed something and want the remote to point at the earlier commit again. This is a history rewrite on the remote. You pushed secrets or huge files and need them gone. This is the most fragile case, because the old objects may persist in forks, pull requests, and caches even after you rewrite the branch.

Each has a different first step, but they all start by identifying the commit you want to return to. Everything else is mechanical.

Prerequisites before you touch anything

Before running any recovery command, set yourself up so a mistake stays reversible:

1: Stop everyone from pushing to the branch. Ask collaborators to hold off, or temporarily protect the branch so force-pushes and normal pushes are both rejected. This removes the biggest source of confusion, which is a second overwrite landing on top of your recovery. 2: Create a safety branch or tag pointing at your current state. For example, git branch backup-before-recovery and git tag safety-2026-11-13 locally. If you have push rights, push the tag: git push origin safety-2026-11-13. Tags on the server are cheap insurance and survive until someone deletes them. 3: Fetch everything, so your local view of the remote is current: git fetch --all --prune. --prune removes local remote-tracking refs for branches that no longer exist remotely, which avoids confusion when a branch was deleted. 4: Note the exact branch name and the remote (origin/main, origin/release/2.4), because you'll need both in every command. 5: Check whether the remote keeps reflogs. Managed hosts generally expose a reflog per branch through their API; bare repositories you control may or may not have core.logAllRefUpdates enabled and a reflog retained.

With those in place, a failed recovery costs you nothing: you still have the tag.

Recovering from your own local reflog

If you pushed the good commit from your machine at some point, your local reflog almost certainly still has it. Reflogs record every time a ref moved locally, and they're on by default for branches you check out and for HEAD.

Start with git reflog show --date=iso or, if you know the branch, git reflog show main --date=iso. You'll see entries like main@{2026-11-10 09:14:02 -0500}: push mixed with commits. The reason field push appears when a push updated the local remote-tracking ref (origin/main), so it's a direct signal that the commit was pushed at that moment.

A worked example: suppose on November 10 you pushed commit a1b2c3d, then on November 12 rebased and force-pushed, then realized the old commit had a fix you needed. Your reflog might show:

a1b2c3d is your target. Verify it with git show --stat a1b2c3d, then create a branch or cherry-pick from it. You don't need the whole old branch; if the one commit is what you need, git cherry-pick a1b2c3d is the least disruptive move.

The limit is real: default reflog expiration keeps reachable entries for 90 days and unreachable ones for 30, so a recovery attempted months later may find nothing. Commits reachable only through the reflog are subject to that 30-day window.

Reading the server-side reflog on GitHub, GitLab, and Bitbucket

If the push didn't originate on your machine, the local reflog won't help. The commit still exists on the server until garbage collection, but you need a way to ask for it.

GitHub exposes two separate things. The branch reflog is available through the REST API at GET /repos/{owner}/{repo}/git/refs/heads/{branch} plus the reflog endpoint, which lists commits the ref previously pointed at. GitHub also has an "Activity" view for a branch in the web UI that shows force-pushes and their before/after SHAs. GitHub's documentation warns that reflog data is temporary and can be pruned at any time, so treat it as a convenience, not a guarantee.

GitLab offers GET /projects/:id/repository/refs?ref_type=branch and, more usefully, an events feed that records "pushed to" and "pushed new" events with before and after commits. The project's "Repository > Commits" page can be filtered by branch, though a force-push may hide older commits from that view even while the objects exist.

Bitbucket Cloud keeps branch-specific activity, and older commit objects remain accessible by SHA for a period. You typically find the SHA in the activity log or in a pull request that referenced it.

In all three, the practical shortcut is the pull request. If the lost commit ever went through review, its SHA is recorded in the PR timeline or in comments, and that SHA is enough to fetch and restore.

Using the remote repository directly when you host it

If you manage the server yourself (a bare repo behind SSH, a self-hosted Gitea or GitLab instance, or a corporate Git server), you may have filesystem access to the object store. This is the most reliable recovery path because it doesn't depend on what an API chooses to expose.

On the server, run git reflog show refs/heads/main --date=iso inside the bare repository. Bare repos keep reflogs when core.logAllRefUpdates is true or always; the default true only logs checked-out branches, and a bare repo has none checked out, so many servers lose these entries unless configured deliberately. If the reflog is empty, look for refs/original/ entries left by git filter-branch, inspect packed-refs for stale entries, and check for orphaned objects with git fsck --unreachable --no-reflogs.

That fsck output lists commits no ref points at. If the lost commit appears there, recover it on the server side with git branch recovered and then fetch. If it doesn't, the commit has been pruned and no amount of local cleverness brings it back; only a replica, a fork, a CI cache, or a developer's clone will have it.

One caution: --no-reflogs in the fsck command means "ignore reflogs when deciding unreachability," which is exactly what you want for finding objects that survived only as loose files. It does not delete anything.

Restoring the commit or branch locally

Once you have the SHA, restoring is the same regardless of where you found it.

1: From a clone that has the object (yours, or one you fetched into), verify it: git cat-file -t a1b2c3d should print commit. 2: Create a branch there: git switch -c recovery/a1b2c3d a1b2c3d. If your goal is to recreate the old branch pointer, use the original branch name instead, but do it before overwriting anything. 3: If the object isn't in your clone, fetch by SHA from the remote where it still exists: git fetch origin a1b2c3d. This works when the server allows fetching arbitrary SHAs; many managed hosts do, but not all, and fetch-by-SHA from a branch you don't own can be blocked for security reasons. 4: Confirm the recovered tree matches what you expect: git log --oneline -5 recovery/a1b2c3d and git diff main recovery/a1b2c3d --stat.

Success check: git rev-parse recovery/a1b2c3d^{commit} returns exactly the SHA you recovered, and the commit message matches your memory. If the SHA resolves but the tree looks wrong, you likely recovered a merge-base or an amended commit elsewhere in the chain; walk the parent links with git log --graph --oneline from the recovered SHA to make sure you have the right point in history.

Putting the remote branch back: revert versus force-reset

This is where the "undo the push" reading lives, and the choice is not neutral. The two options behave differently for everyone else.

Approach Commands Result on history Safe if others pulled? Best for
Revert a merge or commit git revert -m 1 or git revert , then push Adds new commits; old history intact Yes Shared branches, public repos
Force-reset the remote ref git push --force-with-lease origin :main Old commits removed from the branch tip No, until they re-fetch and reconcile Private branches, short-lived overrides

Reverting is the default recommendation on any branch other people use. It preserves the record, keeps clones in sync, and no one's history breaks. The cost is that the branch carries the original commit and its undo forever, and if the thing you pushed was a secret, reverting does not remove it from history.

A force-push with --force-with-lease is the clean rewrite. The lease check refuses the push if the remote has moved since your last fetch, which prevents clobbering a teammate's commit that landed while you were preparing. If the lease is rejected, fetch, inspect what landed, and decide again: don't reflexively --force past the rejection.

A concrete sequence for restore-then-rewind on a branch nobody else has:

1: git fetch origin 2: git switch main 3: git reset --hard a1b2c3d 4: git push --force-with-lease origin main 5: Confirm in the web UI that the branch tip is a1b2c3d and ask collaborators to git fetch && git reset --hard origin/main only if they have local work they can afford to discard.

For the shared-branch case, replace steps 3 and 4 with git revert and a normal push. If the goal is to undo a bad merge rather than a single commit, git revert -m 1 is the standard move; the -m 1 picks the mainline parent, and you should check git log --graph to confirm which parent is "1" before running it.

Recovering after a force-push chain or a deleted branch

Two nastier variants deserve their own method.

A chain of force-pushes. If the branch was rewritten several times, the immediate previous tip may not be the version you want. On GitHub, the branch's activity feed lists each force-push with before and after SHAs, so you can pick the right one. Locally, git reflog --date=iso origin/main shows the sequence of remote-tracking updates, and the commit you want is usually the entry immediately before the push whose message or time you recognize.

A deleted branch. If the branch itself was removed, the commits may still be reachable from a fork, from an open pull request whose head ref survives deletion (many hosts keep the PR's ref alive), or from reflog entries on the default branch if the del was logged. git fetch origin refs/pull/123/head:recovered-123 is the pull-request trick on GitHub, and the equivalent namespace exists on GitLab. Once recovered, push it back as a new branch and, if the name must be the same, delete and recreate the remote branch afterward with normal push access.

If none of these find the commit, check whether anyone had a clone with the branch checked out. A coworker's local origin/main or main reflog is a legitimate source, and it's often the only source once the server has pruned.

When recovery fails, and what counts as a stop condition

Recovery fails most often because neither the reflog nor the object store has the data. The honest stop condition: if the commit is not reachable from any reflog, any ref on any fork or clone, any pull request head, and any CI cache, it is gone, and redoubling commands won't help. The professional move at that point is to ask anyone who might have a local copy to run git reflog and search for the SHA or commit message before they run any cleanup.

Two failure modes to name explicitly:

Fetch-by-SHA returns "not our ref." This usually means the server disallows arbitrary SHA fetches or the object was already pruned. It's not a command syntax error, so retrying won't fix it. The recovered commit exists but the branch won't fast-forward. Expected: a recovery is a divergence, so the push must be a force-push with a lease or a revert, never a plain push.

And the one case that needs expert help rather than a recovery: leaked credentials. If the push contained a secret, history rewriting alone is insufficient. You must rotate the credential, because the commit may already be cached in forks, in PR API objects, and in third-party mirrors. Treat the rewrite as cleanup and the rotation as the actual fix; a security engineer or the hosting provider's support can confirm whether the object was exposed.

What to confirm before you call it recovered

The final verification matters because a recovered SHA that lost a subsequent commit is worse than no recovery at all. Check four things:

The branch tip on the server resolves to the SHA you intended (git ls-remote origin main). The recovered commit's tree includes the files and fixes you care about (git show --stat from the recovered SHA). Any commits that landed after the lost one that you don't want to drop are present in the new history or preserved on a tag. Collaborators' next git pull won't silently resurrect the old tip; a short note in the team channel with the new SHA and a "fetch and reset if you have local work" instruction prevents a confusing re-merge.

If the remote is a managed service, the branch protection rule you created at the start is also the last thing to remove, once everyone confirms they are working against the restored tip.