2

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?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
ghiboz
  • 7,863
  • 21
  • 85
  • 131
  • 1
    Sorry for the downvote, and for the two vote for closing that question as off topic. Don't worry: it is perfectly on topic on Stack Overflow. – VonC Jul 18 '13 at 15:35

2 Answers2

5

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      
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

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
Vikram
  • 4,162
  • 8
  • 43
  • 65