How do I update my branch with master branch and override any changes I made on my branch?

I have my branch called (branch 1) and it has become out of date with the master branch. I want to update branch 1 with the master branch code and I would like to erase any changes that I made on branch 1. I essentially just want to update branch 1 with the most up to date version of the master branch and I don’t care about losing my work on branch 1.

I have looked through stackoverflow and I think I should be doing a git rebase master? but I don’t think that that erases the changes I made on branch 1.

  • Migrating repositories into Github from Stash/Gitlab
  • Show commits for branch on remote
  • How do you set the 16 Terminal Colors for Git-Bash?
  • How can I set merge “No Fast Forward” as the default in TortoiseGit?
  • Git branch maintenance
  • Multiple Submodules with Submodules
  • I just want to make sure. Can someone please confirm?

    I don’t want any changes to be made to the master branch at all. I just want to update branch 1 FROM the master branch.

    thank you!

  • How to list all files in the Git index without newline at end of file
  • how to list all the files that will be affected by `git add .`?
  • Purging file from Git repo failed, unable to create new backup
  • How to configure “git pull --ff-only” and “git merge --no-ff”
  • Using github on my project that uses NuGet
  • Is there any way to get git to work directly with a .pac (proxy auto-config) script?
  • 3 Solutions collect form web for “How do I update my branch with master branch and override any changes I made on my branch?”

    If you are currently on local branch1, do –

    1) git checkout .
    2) git pull

    Make sure your remote upstream is the required branch or you can set the remote upstream by

    git branch --set-upstream-to origin/my_branch

    git rebase master will update your changes locally after getting the changes from the remote master branch.

    Note – If you have made any commits locally, it would be easier to delete the local master branch and create a fresh branch with remote master as upstream.

    You can do this by –

    1) git fetch
    2) git checkout -b new_master origin/master
    3) git branch -D master

    This will create a new branch ‘new_master’ locally deleting the old master branch.

    Or better yet (if you have no local changes in any of the branches) –
    delete your repo and clone the code again!

    Let me see if i can explain in steps :

    1) You need to be in sync with your remote repository . So you do a fetch from your remote …
    (origin is the default remote .. you can also fetch it from other remote if you have configured with different name..)
    COMMAND : git fetch origin

    2) If you dont want anything from you current branch .Then first remove all local changes from unstaged files .stash should take care of this ..
    COMMAND : git stash

    3) Now switch over to master branch .So that you can delete the “branch 1” that you are trying to fix . (This is because you cannot delete the branch that you are already on)
    COMMAND : git checkout master

    4) Delete your old “branch 1”
    COMMAND : git branch -D “branch 1”

    5) create a fresh branch “branch 1 ” out from your remote master
    COMMAND : git checkout -b “branch 1” origin/master

    Note: Source Tree is a great tool that can help you with all this ..

    If you have the GitHub client you can add a basic file to the directory and commit the changes to branch 1. **If you don’t ** you can delete the branch and create it off of the master branch.

    Git Baby is a git and github fan, let's start git clone.