bjorkblom
bjorkblom

Reputation: 1959

Gerrit and feature branches

I'm started to work with feature branches in our repository that's connected to Gerrit but I do facing some issues when it comes to update those feature branches.

What we've done is that we created a feature-branch from master. While we're developing in the feature branch, development is also ongoing in the master. What's the best practices (if any) to update the feature branch with the master branch?

  1. Rebase -> If we rebase from master and push it, all commits from master needs review again in feature branch.
  2. Merge -> It's not allowed to push merge commits.

Upvotes: 3

Views: 4565

Answers (3)

ajay kumar tiwari
ajay kumar tiwari

Reputation: 26

First, we should not do development on master branch, if something is very urgent; we shall make a hotfix branch and use for development. Second, Rebase is always a preferable option to keep updated your feature branch but whole team must perform the 'rebase' only rather 'merge' to keep commit history clean. Finally, as you said rebase and merge won't helping you so you can use the command "git merge --squash", this command will fetch all the new commits, combine and create a one commit change ID. you may need to handle conflicts manually although. process of doing is given below:

  1. git checkout master
  2. git pull
  3. git checkout feature_branch
  4. git pull
  5. git merge --squash master
  6. git add .
  7. git commit -m"commit_message" // resolve all the conflicts in your IDE.
  8. git push

Upvotes: 0

If I understood it correctly you have a feature branch on Gerrit, correct? I mean, you're not just working in a local feature branch, right? If this is correct, you can not do the first option (rebase) and the answer for your question is: 2. Merge.

You also said it's not allowed to push merge commits to Gerrit so, if you really want to update the feature branch with the master, you need to ask to the Gerrit administrators to grant to you (and/or other ones) permission to push merge commits just to this specific feature branch.

Upvotes: 2

Martin G
Martin G

Reputation: 18109

Uplifting a feature branch by merging it with master and pushing that merge to gerrit is super convenient, so you should consider setting different rules for master and other branches in gerrit if possible.

In general i think it makes little sense to not allow merge commits on branches which are uplifted regularly. Why would you not want to show that aspect of the feature development in the commit history? Totally agree with not allowing merges on master though. They don't add valuable information about how development happened there. They only make it harder to see the order of things.

Upvotes: 1

Related Questions