Git: branches and merges

A branch is a movable label on a commit: creating and switching branches, attached or detached HEAD, fast-forward merge or merge commit, deleting a merged branch.

  • 27 cards
  • 6 topics
  • Free

The outline, topic by topic

Each topic is weighted the way the exam weighs it.

  1. Concepts
  2. Questions
  3. Sort and link
  4. The steps
  5. Scenarios
  6. Understand

A few cards from the deck

  • Branch: what is it?

    Show the answer

    A movable label placed on a commit, which moves forward by one step on its own with each new commit made on it.

    Creating a branch copies no file: it writes a name into a file. That is why it is instant, even on a big project.

  • In this history, which commit is the merge commit?

    ```text
    * e59d223 Fusionne menu
    |\
    | * d85f593 Ajoute m
    * | eb18868 Ajoute n
    |/
    * 4a75fff Ajoute b
    * 16efacd Ajoute a
    `

    • e59d223
    • d85f593
    • eb18868
    • 4a75fff
    Show the answer

    e59d223

    The merge commit is where two lines join: e59d223 has eb18868 and d85f593 as parents. 4a75fff is the common ancestor where they split.

  • git … -c menu creates the branch menu and moves onto it; git … main goes back to main.

    Show the answer

    git switch -c menu creates the branch menu and moves onto it; git switch main goes back to main.

    Without -c, the branch must already exist. Before, git checkout was used for both, which was confusing next to restoring files.

  • git switch -c: what is it?

    Show the answer

    Creates a new branch at the current commit and moves onto it right away.

    It is the one-step version of git branch followed by git switch. The uncommitted changes in the working directory follow to the new branch.

  • Bringing a branch's work into main: which step comes after "git switch -c menu to create the branch and move onto it"?

    • Edit the files then git add to stage them
    • git commit -m to record the work on menu
    • git switch main to go back to the branch that must receive
    • git merge menu to bring the commits in
    Show the answer

    Edit the files then git add to stage them

    You always merge from the receiving branch: that is why you go back to main before git merge menu. Deletion comes last, once the commits are in main.