Cant git push to master after returning
I rejected my changes on the remote master by mistake. To keep them safe, I created a branch backup
. Then I rolled back the changes I made to the remote master.
On my local master branch, I ran:
git revert <commit_sha>
and then
git push
Now I have finished working on a new branch (backup) and everything looks good. But I cannot push the changes from the local branch backup
to the remote master. When I run git pull
on my fallback branch, the changes I made are lost. The code is replaced with the content of the remote master.
Is there a way for me to change my changes to the remote master branch without losing my job?
source to share
UPDATE
Since you've already committed revert
to your local branch master
and pushing it to your remote, you should just push all your new changes to your local branch master
and forget about the branch backup
. Be aware that your branch backup
still contains these erroneous codes. If you pushed him towards the remote, you will present the codes that you returned back.
Original Answer
If you are the only person working on this remote repository , you should be able to use
git push -f <remote> <branch>
to force your new branch to go to the remote master branch.
To help with terminology a bit, each git repository has a local branch master
. So saying that I pushed my changes to master doesn't make sense. We either push to the remote (which is marked as by default origin
) or merge with the (local) master.
source to share