Reputation: 8003
My repository have a master
and dev
branch.
At this time I wish merge the dev
with the master
, or better, not a merge, but total replacement the content of the master
branch with the dev
.
Is it possible, and how you would do it with git commands?
Upvotes: 2
Views: 797
Reputation: 4190
Let's say you started with master
...and sometime later you created a dev
branch (from master
HEAD
or some previous commit of master
).
You can also do the following.
# find common ancestor
git merge-base master dev
# This will give you SHA-1 of ancestor like this: `4de51ba41fba357ac9ce63f098451cd1fc2dacbe`
# A hard reset master to this commit
git checkout master
git reset --hard 4de51ba41f
git rebase master dev
# After successful completion you will find yourself checked out on `dev`
# checkout master again and merge dev to get your final result
git checkout master
git merge dev
# Now your master will be same as dev
Upvotes: 0
Reputation: 1323953
This is a "merge" with a "theirs" strategy, which doesn't exist natively.
But you can simulate it through a number a way, as in "git command for making one branch like another"
The one I like is through the creation of an extra branch:
git checkout dev
git checkout -b tmp
git merge -s ours master # ignoring all changes from master
git checkout master
git merge tmp # fast-forward master to tmp HEAD
git branch -D tmp
Upvotes: 5