I have an old dev branch that is completely outdated. I don't want to remove it but I do want to replace its contents entirely with the master branch. Meaning, I want dev_branch = master
I tried:
git merge -s ours dev_branch
Didn't work though...
I have an old dev branch that is completely outdated. I don't want to remove it but I do want to replace its contents entirely with the master branch. Meaning, I want dev_branch = master
I tried:
git merge -s ours dev_branch
Didn't work though...
If you want all changes from master in dev_branch, then:
git checkout dev_branch
git reset --hard master
This only works if other people haven't cloned the repository.
If you have dev_branch pushed to a remote already, you have to do:
git push --force
To force-push to the remote. Warning: This will break the history of the branch for people who cloned it before! Then, other people will have to do a git pull --rebase on the dev_branch to get the changes.
You can also rename the dev branch to something old and then make a new branch from master with the same name:
git branch -m dev_branch old_dev_branch
git branch -m master dev_branch
Or, use the ours strategy — not sure why it wouldn't work for you:
git checkout master
git merge -s ours dev_branch
git checkout dev_branch
git merge master
Why do that? You can delete the branch if it isn't needed anymore (But why? Branches cost next to nothing.). Or you can rename it:
git branch -m dev_branch obsolete_dev
Or you could do this to delete it:
git branch -D dev_branch
Now create a new branch off master (assuming you are on it):
git branch dev_branch
See git branch --help for further options (setting up remotes and all that jazz).
If you now have new branches, you'll have to synchronize with any peer repositories.
Best way to avoid hassle: Have an "active" development branch, if it goes stale, abandon it and create a new one. No history lost that way (could prove crucial sometime).
Have e.g. a branch for each major version, develop on branches off those to fix version bugs, master forges ahead. Use cherry-pick and perhaps merges to port fixes to older versions.
A: A possible reason for why one might not want to delete the branch is that CI tooling might deploy the dev server or a testing server based on that branch, and removing that branch might remove the server, or break it.
– apotek Feb 27 '24 at 16:29
dev_branchto origin (if it had one), and you will also no longer have amasterbranch locally. – aidan Oct 28 '15 at 01:48