From 3464b8a43624f0a795e7a0b2908304cd4a661a70 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Sun, 7 Jun 2015 01:15:33 +0300 Subject: [PATCH] Fill section "Merge or rebase?" --- pep-git.txt | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/pep-git.txt b/pep-git.txt index 1657263..a9b4d9e 100644 --- a/pep-git.txt +++ b/pep-git.txt @@ -383,6 +383,56 @@ https://kernel.org/pub/software/scm/git/docs/howto/revert-a-faulty-merge.html Merge or rebase? ================ +Internet is full of heated discussions on the topic: "merge or +rebase?" Most of them are meaningless. When a DVCS is being used in a +big team with a big and complex project with many branches there is +simply no way to avoid merges. So the question diminished to "whether +to use rebase, and if yes - when to use rebase?" Considering that it +is very much recommended not to rebase published commits the question +diminished even further: "whether to use rebase on non-pushed +commits?" + +That small question is for the team to decide. The author of the PEP +recommends to use rebase when pulling, i.e. always do ``git pull +--rebase`` or even configure automatic setup of rebase for every new +branch:: + + $ git config branch.autosetuprebase true + +and configure rebase for existing branches:: + + $ git config branch.NAME.rebase true + +After that ``git pull origin v2`` will be equivalent to ``git pull +--rebase origin v2``. + +In case when merge is preferred it is recommended to create new +commits in a separate feature or topic branch while using rebase to +update the mainline branch. When the topic branch is ready merge it +into mainline. To avoid a tedious task of resolving conflicts you can +merge the topic branch to the mainline from time to time and switch +back to the topic branch to continue working on it. The entire +workflow would be something like:: + + $ git checkout -b issue-42 # create and switch to a new branch + ...edit/test/commit... + $ git checkout v2 + $ git pull --rebase origin v2 # update v2 from the upstream + $ git merge issue-42 + $ git branch -d issue-42 # delete the topic branch + $ git push origin v2 + +When the topic branch is deleted only the label is removed, commits +are stayed in the database, they are now merged into v2:: + + --o--o--o--o--o--o-M-