Version Control and Collaborative Workflows
Spring 2025
1
Reminder of what we did last week
Today’s Agenda
3
Today’s Agenda
4
Discussion Questions
When you clone a repository what happens? What files are downloaded from the origin?
Makes a local copy of everything:
What commands do you issue to put one of your own local directories under version control? After issuing that command, what happens, specifically?
Git init
What just happened?
What data structures does git use? How do they work together?
Git uses a few core object types: blobs, trees, and commits.
Tl;dr Data Structure Summary
Today’s Agenda
10
Collaborative git workflows
When you start collaborating with other people, the workflow gets more complex. A few other concepts to introduce here:
11
Branching
Branches allow you to create new features (often experimental) without altering the main branch (where the authoritative version of the code lives).
Important ideas:
12
Main
Branch Commands Using git
13
git checkout -b my-new-branch | Creates a new branch |
git branch | Tells you which branch you’re on |
git checkout main | Switches you from your current branch to the main branch |
git checkout my-new-branch | Switches you from your current branch to the my-new-branch branch |
git branch -d my-new-branch | Deletes my-new-branch from your local repo |
git merge my-new-branch | Merges changes from my-new-branch into the current branch. |
git rebase my-new-branch | Rebases changes from my-new-branch into the current branch. |
Understanding Code History
Basic Git History
Feature Branch
You decide you want to make a new login page for your app. You make a new branch called Feature-Branch and make 3 commits Z, Y, and X that collectively have code for the login page. You are now ready to integrate your branch into the main codebase.
What should happen next?
Fast-Forward
Since no one else has made any changes to the repo since you made your branch, you can simply integrate your changes using a “fast-forward”
Feature-Branch When Main is Ahead
New scenario: Since you made your branch, new code (commit D) has been incorporated into the repo that your code doesn’t have.
What should happen next?
Option 1: Merge Commit
A merge commit creates two parent pointers:
Option 2: Rebasing
Option 2: Rebasing
Rebasing involves actually making your code history look like you actually branched from D (your collaborator’s commit). In other words, you “rewrite history”. The steps:
One More Option: Squash
Conflicts
What happens if Commit D and Feature-Branch modify the same file?
Trade-Offs
Merge Commits
Rebase
Class policy decision: rebasing instead of merging
Pull Requests
26
Handling Conflicts
27
Authentication: What is a public/private key pair?
28
Public/private keys on Servers
29