Reuse of a merged development branch / Incorporation into an immutable stable branch with git

Two programmers, A and B, are working on a project with a repository hosted on github:

Deployment exists.

Programmer A creates devBranchA based on the last wizard

master$ git checkout -b devBranchA 

Programmer B creates devBranchB based on the last wizard

 master$ git checkout -b devBranchB 

They decide to merge the stable changes into the master whenever possible.

Agreed Workflow:

[on devBranch]

 git commit -m 'Stuff to make branch stable enough to merge' git checkout master git pull origin master git merge devBranch [fix merge conflicts if any] git checkout devBranch git commit -m 'New cool stuff' 

However, if there have not been any commits since the last merge, then it is not possible to merge devbranch back into master (unless a new dev branch was created, not the previous one)

In this case, when Programmer B arrives to combine his work into a leading branch, it will not be the current intended master, but the state of the master before merging.

Is there a way to automatically force the main branch to update itself to the head of the dev branch when merging if there were no intermediate commits?

What is the intended multi-user workflow when working with git and the centralized github registry? It seems to me that I am not using git as it is intended to be used.

+7
source share
2 answers

Check out git fetch;git rebase origin/master or git pull --rebase , follow the order of commits in the main repository, because it will reinstall by fixing local commits from above. You do not care that the order of local commits is as significant in local branches, because only you have them. Try, but use with caution, for example. duplicate the branch before rebooting, until you get used to it.

In general, you are talking about git workflow, and I found that you need to familiarize yourself with the two main workflows. Keep in mind that I am talking from personal experience on how to minimize conflicts:

  • The first workflow for the database (for the cleanest commit history, pushes the burden of conflict in general to uncommitted code).
  • Combining a workflow (sometimes easier when there are many changes that conflict, I usually use this only as a backup)

Example Initial Workflow

 git checkout master // For the sake of argument, let say the latest commit in your local master is from august 1st or something old like that. git branch temp_branch // copy of the master git checkout temp_branch git add changedFiles;git commit changedFiles; // A change from november 2nd. git log // Now your dev branch has a new commit on top of an otherwise old branch. git log origin/master // You get a listing of the commits from the origin repository, the master branch. 

I usually use origin / master for development, with git tags standing for commits that are made live.

Now here, where the problem arises, and where the choice of the workflow comes into play: let's say there is a commit that came from another dev repository in master, for example. commissioned on October 15th. Perhaps this was commissioned by another developer, perhaps by himself.

Your options: Merge or reinstall.

Combine

Implements additional fixation, honors your local (unpushed) branched history of development over the canonical (source / main) history, creates a little more opportunity for conflicts for other and other branches . Essentially, you say: โ€œMy commit order will be mixed with the master branch fix orderโ€ as opposed to reordering the commit history.

 git merge origin/master // merge commit introduced ... // Resolve any conflicts, and finalize the merge commit. git checkout master;git rebase temp_branch // Move the changes to master. git push origin/master // Pushing changes, including merge commit, to origin/master 

At the end, the commit history will look something like this: August-October-November-MergeCommit

Rebase

No additional commits, honorary characters are not fixed in the canonical repository (origin / master) according to local commits, conflicts that occur usually occur during a commit that the developer has not yet committed (and therefore no one can take into account).

 git rebase origin/master // ... // Resolve any conflicts... git rebase --continue or git rebase --abort ... // Resolve any conflicts... git checkout master;git rebase temp_branch // Get the branch changes without a merge commit into master. git push // Push all changes to the canonical repository. 

Note. If you need to execute more than two conflict resolutions, then the best time is for git rebase --abort and return to the merge.


Try this process, see if it matters to you! This requires some experimentation before you can actually get a tactic that works well for your development in git, I think, because there are so many other approaches when you get decentralized.

+1
source

You can find another illustration of the two workflows mentioned by Tchalvak in his answer in the " git rebase vs git merge " section.

As explained in the section What is the correct git workflow with common function branches? , I prefer to avoid "backward merging" (from master to devBranch ) and would rather reinstall devBranch on top of master , provided that:

  • devBranch merges regularly with the master
  • I reset only the new local commits (which I have not pressed yet).
0
source

All Articles