- Forward


Git
An Introduction to Version Control


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu

Print

Introduction
Back SMYC Forward
  • What is Git?
    • A version control system
  • Important Features:
    • Distributed
    • Multiple Check-Outs
The Important Pieces
Back SMYC Forward
  • Repositories:
    • A repository is an "official" archive
  • Working Trees:
    • A working tree is a directory/folder on a filesystem (with an associated repository)
  • Index:
    • An intermediate collection of changes (that need to be confirmed) before they can be committed (i.e., moved from the working tree to the local repository)
Normal "Centralized" Work Cycle - Getting Started
Back SMYC Forward
  • Create the Central Repository:
    • Often handled by a third-party hosting services
  • Clone the Central Repository:
    • Each developer uses the git clone command
Normal "Centralized" Work Cycle - Day-to-Day
Back SMYC Forward
  • Using the Local Repository:
    • If necessary (e.g., if switching branches), use git checkout to update the working tree to match a specific tree in the repository
    • Make changes to the documents in the working tree
    • If necessary, add new files to the index using git add
    • Commit to the local repository from the index using git commit
  • Pushing New Commits to the Central Repository:
    • Attempt to update the central repository using the git push command
    • In the event of potential conflicts that result from someone else pushing before you (i.e., "non-fast-forward" errors)
      • Use the git pull command (which does both a git fetch and git merge) to incorporate the changes that others have made
      • Resolve any actual conflicts
      • Use git push to update the central repository
Normal "Centralized" Work Cycle - Day-to-Day (cont.)
Back SMYC Forward
  • An Important Objective:
    • Reduce the number of conflicts that must be resolved when pushing later in the day
  • One Way to Achieve this Objective:
    • Perform a git pull (and resolve any conflicts) at the start of the day
  • What This Accomplishes:
    • It makes sure that you have the most recent code pushed by your teammates before you start making more changes
Other Work Cycles
Back SMYC Forward
  • Some Examples:
    • Feature Branching - all feature development takes place in a dedicated branch (not the master branch)
    • Gitflow - a strict branching model designed around project releases
    • Forking - Every developer has a server-side repository
  • Issues:
    • Longer-lived branches are riskier
    • The work cycle should allow for easy reversions (because things do go wrong)
Nerd Humor
Back SMYC Forward
/imgs
(Courtesy of xkcd)
There's Always More to Learn
Back -