Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

coder72's avatar

How to undo a push in git?

I accidentally push branch instead of master So is there any way to revert that push so that i can bring master code ? I am supposed to push master but i push git push origin branch name ? I was in master and i supposed to hit this code and go another branch from master

 "git checkout ProductBranch"

but i accidentally

 git push ProductBranch 

.So i donot want to revert that git push ProductBranch

0 likes
4 replies
automica's avatar

@coder72 if you've pushed ProductBranch to remote, that's fine.

Your master branch isn't effected, all you've done is push the branch from a different branch. The only thing that would be an issue is if you've merged in your ProductBranch.

Check on your remote repo, and see if your master branch took in the new commit. I think all you've done is introduce your ProductBranch to remote. if you don't want that there just delete it.

1 like
lxberger's avatar
lxberger
Best Answer
Level 4

To undo your last (1) commit :

git reset --soft HEAD^1

To undo a specific commit :

git log --oneline --decorate --graph

git reset --hard THE_COMMIT_NUMBER_FROM_THE_LOG

Hope that helps @coder72 !

1 like
coder72's avatar

@lxberger Thanks but

i execute git reset --hard
git pull origin master 
git revert commit-id
automica's avatar

@coder72 what branch did your commit end up on? Or have you just pushed your ProductBranch to remote and you don't want it there?

if you just want to delete it, login via web to your repo (GitHub/ bitbucket) etc or manually run the following

git push origin --delete ProductBranch
1 like

Please or to participate in this conversation.