Home > Net >  Git workflow for feature branches
Git workflow for feature branches

Time:05-23

I created a remote feature branch which has multiple changes. I updated remote branch with master multiple times to keep it up to date. I did merge instead of rebase to avoid force pushing remote branch after rebase.

I need to merge remote branch back to master. What is the preferred way? I would like to have a linear history of all the changes of the remote branch

I did git rebase -i mainline It is showing only the commits made in remote branch without showing merge commits(commits which says merging mainline to remote). Can I use rebase even after merging mainline to remote branch? Can I use the below workflow to merge changes back to master .

 git checkout remote-branch 
 git merge master 
 git push remote

doing it multiple times as remote branch and master progresses.

When it’s time to merge back to mainline

    git checkout remote-branch
    git rebase -i master 

(it is showing only the commits in remote branch without showing merge commits) 

picking up and squashing commits..

    git checkout master 
    git merge remote
    git push 

Is this workflow valid?

Current state and Desired State Image

CodePudding user response:

I did merge instead of rebase to avoid force pushing remote branch after rebase

If you have do a force pushing, unless you make a squash commits that were already pushed, you are doing something wrong.

The normal behavior would be making a fetch of the project, then a rebase onto the mainline, so you put your changes on top of it.

CodePudding user response:

What the picture shows is a squash merge.

GitHub gives you a button for that, as an option for closing an accepted pull request. Nothing needs to be done on your local machine. Just click the button in the GitHub web browser interface, choosing the Squash And Merge option.

If you're not using pull requests, but rather you're merging on your local machine, you'd say merge --squash. But as you keep calling this feature branch "remote", I rather suspect you're supposed to use pull requests.

  • Related