0

I got some git-flow issue. I have a master and a dev branch. My dev branch has updated code and I made a feature branch from it. Now I got a situation that I need same master code in my existing dev branch.

I have few solutions but I don't know which is best practice:

  1. Make another dev branch and delete the existing one.
  2. Delete existing code from dev and make it the same as master.
k0pernikus
  • 41,137
  • 49
  • 170
  • 286
Usman Saleh
  • 509
  • 4
  • 8
  • 1
    You can also merge in the remote master in your development branch or rebase you dev branch against the master branch. "Best practices" depends if you want to keep the history as is (then merge) or if you want to avoid merge-commits and a tango-history (then rebase). – k0pernikus Jan 22 '20 at 10:51
  • k0pernikus no i have a different situation, `dev` is ahead from `master`, but now i don't need existing dev branch that's why I just want to move dev code to another branch and replace dev same as the master. – Usman Saleh Feb 03 '20 at 06:27

2 Answers2

1

You could do one of the followings:

  • Make a Pull Request from the master branch to the dev branch, this way you could pick what changes from master you want in the dev branch (Probably would result in a merge conflict).
  • Open a new dev (You should delete the old dev first) branch from master, this way both of them will be sync.

If you don't care about the content of dev and you need EXACTLY the same code that is already on master I'll recommend the second, it's faster, but it's a better practice to do this kind of things with a Pull Request.

k0pernikus
  • 41,137
  • 49
  • 170
  • 286
Alberto Perez
  • 1,937
  • 9
  • 19
1

If you're working alone on the repo, consider simply moving the ref of dev with

git branch -f dev master

That being said, your feature branch, having been branched off dev, might still reference commits from the old dev you wanted to forget, and they'll be brought back in when you merge into master. Be sure to anticipate it if that's the case.

Comment if my assumption is false (if you're sharing the repo), I'll update my answer.

RomainValeri
  • 14,254
  • 2
  • 22
  • 39