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?

5
  • 2
    Why you want it in so complicated? Why not just git reset --hard dev? Commented Jul 4, 2014 at 10:36
  • @AlexeyTen Because I don't know if Git reset --hard dev do what I want to do? What is it doing? Commented Jul 4, 2014 at 10:41
  • It will make current branch (say master) to be exact copy of dev. See git-scm.com/docs/git-reset Commented Jul 4, 2014 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 Commented Jul 4, 2014 at 10:47
  • possible duplicate of Force my local master to be origin/master Commented Jul 4, 2014 at 11:22

1 Answer 1

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 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.