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)?

  • Renaming local GIT branch does not change name on 'Origin'
  • Git fetch and pull operation on branches
  • Is git-svn dcommit after merging in git dangerous?
  • Keep files on working tree but make them available to any branch?
  • Rename merged branch name in bitbucket
  • Recover unreferenced commits from remote git repository
  • Gitlab installation based on gitolite fails
  • Bringing changes to an experimental branch from a new commit in git svn
  • Why use git reset here instead of git merge?
  • How to setup the Output and Intermeidate directory in visual studio to be dependent on current git branch?
  • git tag: fatal: Failed to resolve 'HEAD' as a valid ref
  • Git - did init bare in wrong directory
  • 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:


    git checkout <your-branch>
    git reset --hard master
    git push -f origin <your-branch> #WARNING DANGEROUS COMMAND!!!!


    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>
    Git Baby is a git and github fan, let's start git clone.