0

I have two branches say master and dev.

Master is old and I want to put dev into master so effectively:

  1. Delete all files in master,
  2. Copy all files from dev into master
  3. so at that time, master and dev became the same, without merging dev into master.

I can do this in the following way:

  1. Checout dev branch.
  2. Make a copy of dev branch some where on my hard disk.
  3. delete .git from the copy of dev branch on my hard disk.
  4. checkout master branch
  5. Delete all files other than .git in working dir.
  6. Copy all files from dev into working dir (all files are the same as dev branch other than what is in .git directory, but it is in master brach now)
  7. Commit master branch.

But I am wondering what is the correct way to do this in git?

Maroun Melhem
  • 3,100
  • 1
  • 20
  • 22
mans
  • 17,104
  • 45
  • 172
  • 321
  • 2
    Why you want it in so complicated? Why not just `git reset --hard dev`? – Alexey Ten Jul 04 '14 at 10:36
  • @AlexeyTen Because I don't know if Git reset --hard dev do what I want to do? What is it doing? – mans Jul 04 '14 at 10:41
  • It will make current branch (say master) to be exact copy of dev. See http://git-scm.com/docs/git-reset – Alexey Ten Jul 04 '14 at 10:45
  • @AlexeyTen So to use it, I should be in master branch and give that command to hard reset my branch to dev – mans Jul 04 '14 at 10:47
  • possible duplicate of [Force my local master to be origin/master](http://stackoverflow.com/questions/16103810/force-my-local-master-to-be-origin-master) – eckes Jul 04 '14 at 11:22

1 Answers1

1

This is pretty simple to solve - use branch rename to rename the existing master branch, and then checkout a new branch named master from the dev branch

git checkout dev
git branch -m "master" "master_old"   #rename existing master branch
git checkout -b master                #recreate master from dev

Additionally, push your new master branch upstream using

git push upstream -f master

If now you do a git branch, you will see

$) git branch
  dev
* master
  master_old
Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186