Version Control#

Learning Objectives#

  • Understand the importance of version control in managing file changes and collaboration

  • Differentiate between git and GitHub and their respective roles

  • Execute a basic Git workflow, including creating a repository, cloning, modifying files, and pushing changes

  • Identify alternatives to GitHub and their features

  • use Git commands to manage and track changes in a project effectively

Version control is an essential process for managing file changes over time, particularly in software development and document management. As part of Coding for Reproducible Research has a dedicated course to Git and Version Control avaliable

Introduction to Version Control#

Version control allows us to track changes in files over time and revert to earlier versions when needed. It serves multiple purposes:

  • History and Documentation: Keeps a record of changes and the reasons behind them.

  • Collaboration: Enables multiple people to work on the same project without conflicting changes.

  • Backup: Acts as a backup mechanism by saving different versions of files.

Git and GitHub#

What is Git?#

Git is a version control system that helps manage changes to files and coordinates work among multiple people. It is highly favored in the software development industry due to its robustness and flexibility.

What is GitHub?#

GitHub is a web-based platform that enhances Git’s capabilities by providing a centralized location for hosting Git repositories. It facilitates collaboration among project team members and integrates various project management tools.

Alternatives#

While GitHub is widely used, other platforms like GitLab (including a self-managed instance by the university where you can sign in with your university credentials) offer similar functionalities.

Basic Git Workflow#

This section provides a step-by-step guide to demonstrate a basic workflow using Git and GitHub. It is essential for understanding how to effectively manage a project’s changes.

Create a Repository#

  • On GitHub, create a private repository (e.g., test-repo) and initialize it with a README.md file.

Clone the Repository#

  • Clone the repository to your local machine using the command: git clone [web-URL]

  • Example: git clone https://github.com/username/test-repo.git

Modify Files#

  • Open and modify the README.md file, for instance, adding a description like “A test repository created for demonstration purposes.”

Check Status#

  • Use git status to see the changes made.

Add Changes#

  • Stage changes for commit: git add README.md

  • Verify by checking status again with git status.

Commit Changes#

  • Commit the changes with a message: git commit -m "Add description to README.md"

  • Check status to confirm the commit.

Push Changes#

  • Push the changes back to the GitHub repository: git push

  • Confirm the changes on GitHub.

Important Tips

  • Avoid cloning repositories to locations synchronized to cloud services like OneDrive to prevent sync conflicts.

  • Familiarize yourself with the Modify-Add-Commit cycle to manage changes effectively.

  • Branches are useful for collaboration, allowing multiple parallel developments on the same project.

By mastering Git and GitHub, you enhance your ability to manage projects efficiently and collaborate effectively. It is recommended to further explore these tools through additional courses and resources.

Adapted Content From:

Summary Quiz#