How to copy one branch to another regardless changes?
I’m relatively new to Git; I usually use SVN.
We have several branches. Because I have not used my branch for a while, the master branch is far ahead of my branch. How can I copy master branch to my branch regardless my changes (both locally and remotely)?
One Solution collect form web for “How to copy one branch to another regardless changes?”
suppose you want to remove all changes to your local branch and start again from master:
THE FAST METHOD
git checkout <your-branch> git reset --hard master git push -f origin <your-branch> #WARNING DANGEROUS COMMAND!!!!
THE LONG METHOD BUT MAYBE EASIER TO UNDERSTAND
go to master branch
git checkout master
now delete your branch, including all your work on that branch!
git branch -D <your-branch>
now recreate the branch on master, since you are still on master, you can just do:
git checkout -b <your-branch>
now push this to remote. You need to force pushing to remote, which is dangerous since you are changing your history on the remote (agreed, only for your-branch now)
git push -f origin <your-branch>