Git Basics

Michael L. Collard, Ph.D.

Department of Computer Science, The University of Akron

Version Control Systems

  • The platform on which software is developed and distributed in modern software engineering
  • Tracking and controlling changes to files used in software projects
  • Essential to coordination of changes among multiple developers
  • Stores history of project for record-keeping, safe-keeping, and analysis
  • Most important tool (after editor and compiler) for software development
  • Defines workflow. More time/energy/effort may be spent in version control then any other tool

Git

  • Distributed version control system
  • Used by most major open-source projects, e.g., Linux kernel
  • Used by major companies, e.g., Microsoft, Apple
  • Built-in to many IDEs
  • Fluency in Git is a requirement for anybody in software engineering

GitHub

  • Web-based hosting site for Git repositories
  • > 85 million repositories, > 28 million users
  • Being purchased by Microsoft
  • An account at GitHub is strongly encouraged for anybody in software engineering

Git Local Account Setup

git config --global user.name "Michael L. Collard"
git config --global user.email collard@uakron.edu
git config --list

Git Local Repository Setup

git clone <URL>

Git Tools

Git Basic Workflow

  • Pull any new commits in the remote repository, e.g., GitHub, to the local repository:
    git pull
    
  • Edit files locally, e.g., added user stories to file UserStoryReport.md
  • Commit current changes to the local repository:
    git commit -am "Add user stories"
    
  • Push the new commits in the local repository to the remote repository, e.g., GitHub:
    git push
    

Workflow Notes

  • Only have to pull once per session (but no harm in doing so multiple times)
  • You can wait to push, e.g., if you are offline
  • Use this workflow as you develop (write), not just at the end

Commits

  • Commit as you finish parts of the work, not just at the end of the work. In general, you cannot commit too often, but try to commit complete thoughts (something you can write a good commit message for)
  • Think about the commit messages you are using. Note that they are commands. They finish the sentence:
    • If applied, this commit will <commit message>