Rahul Yadav
Rahul Yadav

Reputation: 3207

How to maintain parallel dev branches and frequently pull from and push to master?

We have a master branch and each developer has his own dev branch(not feature branch) for example dev-john, dev-rahul etc

Now john takes frequent pulls from master to dev-john and makes frequent commits to dev-john

He occasionally merges his commits on dev-john into master without closing dev-john

I need a git flow where all commits after the last merge are merged into master as a single commit with a commit message

I have tried to explain what I need in the graphic below enter image description here

could anyone advise the git commands to run at every stage of this flow

flow modify suggestions are also welcome

Upvotes: 0

Views: 78

Answers (1)

Marina Liu
Marina Liu

Reputation: 38116

Assume the commit history for now looks like (Mx for the merged commits, Rx commits are the common commits on dev-rahul branch, Dx commits are the common commits on master branch, Jx commits are the common commits on dev-john branch):

…--------R1--------M3---R2---R3---R4---R5      dev-rahul
           \      /                     \
…------D1---M2---D2--------M4---D3-------M6    master
        \                 /      \
…---J3---M1---J4---J5---J6--------M5           dev-john

Then you can use below commands to squash the commits after (squash commits M4, D3 and M6 into one commit, as the commit S in below graph):

git checkout master
git reset --soft HEAD~3
git commit -m 'squash commit S for commits M4, D3 and M6'

And the commit history will be:

 …--------R1--------M3---R2---R3---R4---R5    dev-rahul
           \      /                     
…------D1---M2---D2------S                   master
        \              \
         |              M4---D3    
         |              |      \
…---J3---M1---J4---J5---J6------M5           dev-john

Upvotes: 1

Related Questions