Git Workshop
POSTS

Alice: merging without conflicts

Alice knows that branches must be integrated often to avoid problems, so she will merge the vocabulary branch with the main one.

Lab

  • First, she checks that she is in the main branch
git branch
  • Now, she checks the differences between both branches
git diff main vocabulary-chapter-01

Screenshot of the differences between both branches

  • There are some long lines, so maybe it would be better to get the difference without using delta. To deactivate it, Alice just pipes the output of git to another command
git diff main vocabulary-chapter-01 | cat -  # diff without using delta
  • This is the moment to create a new commit with the content of both versions merged
git merge vocabulary-chapter-01 -m "Merged vocabulary"
  • Now the main branch contains all the words, plus the stranger’s profession:
 cat chapter-01.md \
   | grep -e sand -e shore -e beach -e "lighthouse keeper" -C 9999 --color
  • The log of the main branch will include the changes performed on the merged one:
git log
  • As time passes and we keep adding commits to the history, it is more and more convenient to simplify the output of the log
git log --oneline
* And once we start to merging different branches, it is always nice to be able to see the different timelines of our project visually:
git log --oneline --gr███

Solution

git log --oneline --graph

Diagrams

Diagram of a merge without conflict

    Quick access

    1. Introduction
    2. Alice: repo initialization
    3. Alice: first commits
    4. Alice: moving through the timeline
    5. Alice: basic branching
    6. Alice: merging without conflicts
    7. Alice: merging with conflict resolution
    8. Alice: tagging
    9. Bob: cloning repositories
    10. Bob: pushing to origin
    11. Alice: merging and log format
    12. Alice: centralized repository creation
    13. Bob: pulling
    14. Bob: recovering from errors with the reference log
    15. Bob finds the author of a typo
    16. Alice: amending commits
    17. Alice: history simplification
    18. Alice: cherry picking changesets
    © Git Workshop 2023