I have a remote branch that is the basis for a pullrequest.
I mainly worked on a different branch, however that should now replace the old branch.
I tried to do a git push remote oldBranch -f but that only pushes my latest local oldBranch to the git server instead of the current branch - no matter which branch i am currently on.
How can I replace the remote branch with my local branch?
EDIT: If anybody else is interested, this is how i got this to work:
git checkout oldBranch git branch -m 'oldBranchToBeReplaced' git checkout newBranch git branch -m oldBranch git push myrepo oldBranch -f
What you basically want to do is to force push your local branch, in order to overwrite the remote one. If you want a more detailed explanation of each command, then see my long answers section below. Warning: force pushing will overwrite the remote branch with the state of the branch that you're pushing.
In order to switch to a remote branch, make sure to fetch your remote branch with “git fetch” first. You can then switch to it by executing “git checkout” with the “-t” option and the name of the branch.
You can use the local-name:remote-name syntax for git push:
git push origin newBranch:oldBranch This pushes newBranch, but using the name oldBranch on origin.
Because oldBranch probably already exists, you have to force it:
git push origin +newBranch:oldBranch (I prefer the + instead of -f, but -f will work, too)
To delete a branch on the remote side, push an "empty branch" like so:
git push origin :deleteMe
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With