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.
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.
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.