Skip to content

v5 Week 06: A Deeper Look at Git

Reid Russom edited this page Oct 8, 2024 · 3 revisions
Week Topic Learning Objectives Key Resources
6 A Deeper Look at Git Students will be abel to develop a better understanding of git version control and command usage in the command line. Week 6 Slides TBD

Overview

Git Branching

What are Git branches?

  • Pointers to a snapshot of changes
  • Used to add new features or fix bugs in isolation
  • Keeps the main branch free from questionable code
  • Lightweight compared to other VCS models

How Git branches work

  • Represent an independent line of development
  • Abstraction for the edit/stage/commit process
  • New commits are recorded in the history for the current branch
  • Tightly integrated with git checkout and git merge commands

Common options

  • git branch: List all branches
  • git branch <branch>: Create a new branch
  • git branch -d <branch>: Delete a branch (safe operation)
  • git branch -D <branch>: Force delete a branch (even with unmerged changes)
  • git branch -m <branch>: Rename the current branch
  • git branch -a: List all remote branches

Creating branches

  • Branches are pointers to commits
  • Creating a branch does not change the repository, only creates a new pointer

Creating remote branches

  • Configure and add a remote repo to the local repo config
  • Push a copy of the local branch to the remote repo

Deleting branches

  • Delete a branch after merging it into the main code base
  • Use -d flag for safe deletion (prevents deleting unmerged branches)
  • Use -D flag to force delete a branch (be cautious)
  • To delete a remote branch, use git push origin --delete <branch> or git push origin :<branch>

Git Merge

How it works

  • Combines multiple sequences of commits into one unified history
  • Finds a common base commit between the branches
  • Creates a new "merge commit" that combines the changes of each queued merge commit sequence

Preparing to merge

  • Confirm the receiving branch with git status and git checkout
  • Fetch the latest remote commits with git fetch and git pull

Merging

  • Execute git merge <branch> to merge <branch> into the current branch

Fast-forward merge

  • Occurs when there is a linear path from the current branch to the target branch
  • Git moves the current branch pointer to the target branch tip
  • No new commit is created

3-way merge

  • Occurs when the branches have diverged
  • Uses a dedicated commit to tie together the two histories
  • Useful for integrating longer-running features

Resolving conflicts

  • Occurs when both branches have changed the same part of the same file
  • Git stops before the merge commit and asks for manual resolution
  • Conflicts are marked with <<<<<<<, =======, and >>>>>>>
  • Resolve conflicts by editing the affected files and staging them with git add
  • Commit the changes to complete the merge

Optional: Algorithms

  • Intro to algorithms
    • Solving problems using algorithms
    • Use of algorithms
      • Web development
      • Mathematics
      • Operations Research
      • Artificial intelligence
      • Data science
  • Pseudocode

Assignment Rubric

No coding assignment this week - students are practicing GitHub workflow.

Key Pages

Overview of the wiki.

Onboarding guide for new volunteers.

Links to pages for specific assignments, including rubrics, overviews of student content, and mentor-created resources.

Clone this wiki locally