Version control using Git

This lesson aims to teach version control using git and gitlab. We target researchers from novice to intermediate, and cover the basics of git with gitlab for individual use and also for collaboration.

We start from own local repository, branching and merging (locally), and a brief introduction to pushing to remotes. As a continuation, we focus on the use of git for collaboration and sharing. Why is this relevant to researchers?

  • Sharing by email or manually: isn’t fun and doesn’t scale, projects are limited to the time and cognition of one person.
  • One person’s repository on the web: allows one person to keep track of more projects, gain visibility, feedback, and recognition.
  • Centralized: everyone can directly update the same repository. Good for small groups.
  • Distributed: anyone can suggest changes, even without advance permission. Maintainers approve what they agree with. In research environemtn, being able to share more easily is transformative because it allows collaboration and dessminate research results easily and makes projects to scale to a new level.

In this lesson we will learn how to keep repositories in sync and how to work with remote repositories on Gitlab.

The goals of the module as a whole are that the user will feel comfortable about staging changes, committing them, merging, branching and be able to use git with gitlab for collaboration.

The guacamole example that we use is inspired by Byron Smith, for original reference, see this thread. If you are teaching this lesson, see the instructor’s guide.

Prerequisites

  • A reasonably recent version of Git should be installed.
  • Being comfortable with the command line. No expertise is required, but the lesson will be mostly taken from the command line.
  • Participants should be familiar with using a text editor on their system. Emacs and Vim are excellent choices if you know how to use them but Nano or Notepad on Windows are sufficient.
  • Git should be configured prior to the lesson following installation instructions.
  • A GitLab account on https://gitlab.com.

Schedule

20 min Motivation Why version control?
Why Git?
How to organize projects for collaboration using gitLab?
35 min Basics of Git What is Git?
What is a repository?
How does Git operate?
How do I make commits?
How do I select what to commit?
20 min Using the Git staging area What should be included in a single commit?
What is the git staging area? What commands use it?
20 min Rollback using Git How can I undo things?
35 min Git branching and merging How can I or my team work on multiple features in parallel?
How to combine the changes of parallel tracks of work?
How can I permanently reference a point in history, like a software version?
30 min Conflict resolution in Git How can we resolve conflicts?
How can we avoid conflicts?
20 min Sharing repositories online How can I set up a public repository online?
How can I clone a public repository to my computer?
How does version control scale from 1 to N users per repository?
45 min Inspecting history using Git How can we find out when exactly a line of code was changed?
How can we navigate past versions of the code?
How can we find out which commit broke or changed a functionality?
20 min Copying, sharing, and synchronizing repositories How can we backup repositories?
How can we share repositories with others?
How can we keep repositories in sync?
What are different ways to make a copy of the entire repository?
60 min Centralized workflow How can we collaborate with others within one repository?