Merging, branching and rebasing

The setup script is located in the git.zip file in the exercsises folder.

Run ./branches.sh for setup!

Introduction

This exercise has a git lga and git po alias configured:

# git lga will show all commits over all branches
git config --local alias.lga ="log --graph --all --pretty=oneline"
# git po will print the content of a git object
git config --local alias.po="cat-file -p"

Run git branch to see what branches are available

  anotherbranch
  ffbranch
* main
  rebasesource
  rebasetarget

Cherry-Pick

Now, we perform a cherry pick.

Instructions

  1. Make sure you are on the "main" branch
  2. Create and switch to "cherry" branch (git switch -c cherry)
  3. Run git lga
  4. Pick the commit with the message "cherry-pick me" and perform a cherry pick (git cherry-pick commitHash)

Questions

Answers

Merging (Fast-Forward)

Next we perform a merge of branch "ffbranch" into "main". This will be a fast-forward merge.

Instructions

  1. Make sure you are on the "main" branch
  2. Run git lgaand make note where the HEAD point to
  3. Run git diff main..ffbranch to see what changes you gong to pick
  4. Run git diff ffbranch...main to check for "commits" on main but not on "ffbranch"
  5. Merge ffbranch into main

Questions

Answers

Merging

This time we will perform a merge resulting in a merge commit. We will merge "anotherbranch" into "ffbranch". There will be conflicts.

Instructions

  1. Make sure you are on the "ffbranch" branch
  2. Run git diff ffbranch..anotherbranch to see what changes you gong to pick
  3. Run git diff anotherbranch...ffbranch to check for "commits" on main but not on "ffbranch"
  4. Merge "anotherbranch" into "ffbranch"
  5. Optional: Run git merge --abort to abort the merge, then start it again.
  6. Run git diff to inspect the conflicts in the combined diff format.
  7. Resolve the conflict in "ff.txt" by not accepting the changes from "anotherbranch" and stage the file
  8. Stage the file "additional.txt" as it is
  9. Run git status, two files should be staged
  10. Run git merge --continue and remove the comments from the "Conflicts" details
  11. Run git log

Questions

Rebase

Last but not least we will perform a rebase. We will rebase "rebasetarget" onto "rebasesource". The histories of this branch are identical to "ffbranch" and "anotherbranch" before the merge from above.

Instructions

  1. Make sure you are on "reabasetarget"
  2. Run git rebase reabasesource
  3. Optional: Run git rebase --abort to abort the rebase. Then start it again.
  4. Column1. Add "additional.txt" without resolving the config (git add additional.txt)
  5. git rebase --continue
  6. Edit "ff.txt" to only keep the changes from the "add explainer" commit
  7. Add "ff.txt" (git add ff.txt)
  8. Run git bease --continue to complete this rebase

Questions