Version Control

ITEC 3870 Software Development II,
Anca Doloc-Mihu and Cengiz Günay

(License: CC BY-SA 4.0)

Prev - Teamwork, Next - Github Social Computing

Why Version Control?

Advantages:

  • Track changes, keep logs of past development
  • Automatic backups/safety net
  • Concurrent versions: XP vs. Win8
  • Allows teamwork

Teamwork on the same codebase: How?

Seriously, how?

Teamwork: No control? Overwrite chaos!

Teamwork: Locking

Teamwork: Merging

Merging example

Each commit increments version

Github for version control

git is the program behind Github

Common usage scenario:

  1. git clone gets working copy from repo
  2. Make changes in local working copy
  3. git add <files...> to select your changed files
  4. git commit saves your changes into the version control history with a comment (Wash, rinse, and repeat step 2. Commit often!)
  5. git push publishes your previous commits to remote repository (Github)
  6. git pull receives latest changes from repo to sync

Useful commands: Investigating the past

  • git diff shows your changes from last repo version
  • git log [filename] lists all commits, optionally those touching a filename
  • git diff <commit> shows changes in version labeled as <commit>
  • git checkout <commit> rewinds all files back to a version

Challenge: How to find a bug

  1. You have been messing with the code
  2. Suddenly you realized you broke the program
  3. How do you find when was the bug introduced?

Hint: use git checkout <commit>

Parallel development: branches and merging

Many ways to do it, but recommended way:

  • master or main for releases
  • develop for active development
  • Optional: open one branch per feature, e.g. feature-xyz

Relevant Git commands:

  • git switch xyz for switching all your code to branch xyz (without losing if you committed all)
  • git merge xyz for merging all the changes in branch xyz onto current branch
  • resolve conflicts (see your assignment)

Common issues with Git

Avoiding bloating and conflict hell:

  • The .gitignore file: Add lines of file patterns to be kept out of your repo.

Mac vs PC guy: different line endings:

  • Can create a lot of trouble when sending/receiving files between Mac/Linux and Windows
  • Git has settings for it: core.autocrlf will automatically convert for you!

Removing already deleted files from your repo:

  • git add -u files...

Highly recommended visual interface:

  • SourceTree
  • Visual Studio Code plugin for Git

Git Resources

Credits

  • Opening comic from Return to Zero by EEworldonline.com
Home