How to replace one git branch with another?

Member

by denis , in category: Third Party Scripts , 7 months ago

How to replace one git branch with another?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by aubrey , 7 months ago

@denis 

To replace one git branch with another, you can follow these steps:

  1. Checkout the branch that you want to replace with another branch:
1
git checkout branchToReplace


  1. Reset the branch to the commit of the branch you want to replace it with:
1
git reset --hard branchToReplaceWith


  1. Force push the changes to the remote repository to overwrite the existing branch with the new branch:
1
git push origin branchToReplace --force


Please note that force pushing can be dangerous, as it overwrites the history of the branch. Make sure you are aware of the consequences before proceeding with this action.

Related Threads:

How to transfer one repo to another repo in git?
How to check if one file is newer than another in git?
How to branch from deleted branch in git?
How to replace more than one character in oracle?
How to replace one query string via .htaccess?
How to pass value from one controller to another in laravel?