How to work efficiently with branch in git?

Asked

Viewed 1,088 times

12

I’m trying to define a working scheme to keep my repository on Github organized, but it is difficult to reach a solution.

My "idea":

I thought about keeping the branch in the remote repository master (default) and develop. The branch master will be blocked, will only accept merge after review of pull-request, i.e., contributors will send their contributions to the develop and generate a pull request of this for master.

The Feature/foo, Hotfix/foo and other branches will be branched from the develop, I don’t know if it would be interesting to branch even more with branch topic. Before merging the local branch with develop, should be evaluated the need to apply a full rebase or some commit, aiming to maintain a clean and easy to read historical line, after local merge and push to remote, a pull-request from the master <- develop.

In the text so it was already possible to observe some doubts, we will consolidate them and some more:

  • In practice branch topic are really useful and used?
  • Local rebase before push is a good idea, in which situation it would be advisable?
  • It would be more advisable to change my CHANGELOG.Md file in the develop branch, or create a release branch, change there and then merge with master and develop?
  • When merging a master <- develop, should I use merge request (which takes all merge commit + 1), or merge squash (which generates only 1 output commit)? Because of your suggestion?

Due to the importance of the next topic, I decided to separate it from the previous ones:

When I will perform a pull-request master <- develop a conflict in will always occur, this is referring to the file CHANGELOG.Md, whereas new data is always entered at the top, git will always file a change for which an automatic merge cannot be executed. How to solve this problem?

Possible solutions:

  • In the case of Github this suggests to merge the develop <- master, resolve the conflict, apply the control commit, and complete pull-request/merge;
  • I create a release branch from develop, merge release\xxx <- master, resolve conflicts, apply proper commit, perform merge master <- release\xxx and develop <- release\xxx;
  • Or would you have another "better" approach? By best I mean community approaches to collaborative projects, which are proven to be but efficient.

Final doubts:

By following the wake of git flow, after creating the branch release, should merge this with the mater and develop, whereas my master is protected in Github (accepting merge only via pull request), should I upload this branch to the remote and generate the pull-request for the master? And to develop it, I merge locally and push?

Note: I believe that this doubt is part of the head of many people.

  • 3

    Tip: do not branch hotfix of develop. If it’s hot it’s in production, so it branches off the master. It may even be that the pull request is done by someone less experienced in develop, but trying to branch out from it is quite complicated. I treated something about branches and tags in a reply. More here

  • 1

    Gitflow does all this proce =)

  • 1

    I don’t understand why CHANGELOG.Md generates conflict because the data is at the top of the file

  • https://danielkummer.github.io/git-flow-cheatsheet/index.pt_BR.html

  • https://medium.com/trainingcenter/utilizando-o-fluxo-git-flow-e63d5e0d5e04

  • @Andrefigueiredo git checkout master && git merge release/v1.0.1 should still be merged with develop, correct? Another question, it does the local merge, this would be equivalent to me go to the master and do a pull (considering that the master is already updated)?

Show 1 more comment

2 answers

5


  • I understand, but some doubts still linger in the air. For example: after generating the release branch, the merge of this branch has to be done in master and develop, consider that my master is protected, only accepts pull-request. So it would be appropriate to merge in develop and a pull-request in master? What is the real mat in a real project?

  • The release branch is created from the develop and utlizo for final changes in the approval period, for example. This branch will only be merged with master for deployment in production.

  • All the doubts were slowly resolved, however, today the following question arose: why I merge the release branch in master and then in develop, would not be more appropriate after the merge in master, simply to merge --ff no develop to have something like commit xxx (HEAD -> develop, tag: v1.0.0, master)?

  • 1

    You can have small changes from the moment you generated the release branch, when you actually finish the release and go to make the turn to production, you will update the master that represents production and develop that has not yet been contemplated with these small changes.

0

Come on, since many of the doubts kept hammering in my head, I decided to study the subject a little but in depth. Considering the knowledge acquired, I will try to answer the questions that previously represented absolute doubts:

  • In practice, branch topic are really useful and used?

Branch topic can be used to have greater control of "long" outflows. Features that generate many steps can be divided into branch topic, so a more detailed timeline can allow for more controlled partial regressions; in this case the topic branch is relevant (useful), so it’s a great scenario to use this approach.

  • Local rebase before push is a good idea, in which situation it would be advisable?

Yes, it is valid for changes that have not yet been pushed into the remote repository. Situations may be the most several possible, as a commit to change an incorrect comment in the code, correct an error that should not be present in the previous commit, such as forgetting a line delimiter, among others. In short, especially when we generate unnecessary commit, but use this feature wisely, try not to rebase if you’ve already pushed the commit to the remote.

  • It would be advisable to change my CHANGELOG.Md file in the develop branch, or create a release branch, change there and then merge into master and develop?

Preferably in the release branch, this is a branch created to prepare the release of a new version... Therefore, in this branch we can consolidate a CHANGELOG already with the appropriate references to the commit that contain the aforementioned changes, change data in README or make other small adjustments.

  • When merging a master <- develop, should I use merge request (which takes all merge commit + 1), or merge squash (which generates only 1 output commit)? Because of your suggestion?

The merge request in my opinion allows greater traceability, control and readability of the history

Final doubts:

  • By following the wake of git flow, after creating the branch release, should merge this with the mater and develop, whereas my master is protected in Github (accepting merge only via pull request), should I upload this branch to the remote and generate the pull-request for the master? And to develop it, I merge locally and push?

Depends. If the lock in master has been released to contributors or admins, the merge to the master can be done locally and then pushed. If it is blocked even for Admins, a pull request can be generated from a release branch to master, or even from the develop itself.

Following workflows like git-flow is something interesting and very valid, but it’s good to keep in mind that each project has its own features and approaches, so you need to modify management processes whenever necessary.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.