How to Undo or revert git push in gitlab?

Viewed 1747

I accidentally push branch instead of master.

So is there any way to revert that push so that I can bring back the master code? I am supposed to execute this command to go another branch from master:

git checkout ProductBranch

but accidentally I executed this:

git push origin ProductBranch
1 Answers
"git push origin ProductBranch"

If ProductBranch was previously pushed, you could force pushed its last state with:

git log ProductBranch
# make sure the history is the correct one, without your new commits
git push --force origin ProductBranch:ProductBranch

If ProductBranch was never pushed before, then you might consider deleting it on the remote side:

git push --delete origin ProductBranch

Then, simply switch to master and push that:

git switch master
git push -u origin master

If you had committed to the wrong branch, you can fix those commits back to master before pushing.

Related