Git and Version Control
Introduction to Git and Version Control for Collaborative Projects
Abstract¶
This notebook introduces Git and version control, focusing on collaborative workflows for data analysis projects. It covers Git basics, configuration, and integration with Visual Studio Code, including the use of the GitLens extension. Participants will learn how to manage repositories, track changes, and collaborate effectively using GitHub. Practical exercises and resources are provided to enhance understanding and application.
Git and Version Control¶
Objectives of this chapter¶
This chapter will explain the Git tool useful for working with version control in Python, specifically in Visual Studio (you can also use other programming languages...).
- The main focus: Git, its syntax (syntax).
- Using the GitLens plugin in VS Code
- How to work collaboratively on an analytical project using GitLens in VS Code
Git¶
Ok, you already know the basics of Python programming, in the VS Code environment. You create collaborative projects with friends, but you keep getting versions wrong. You would like to work on them together and see and note your progress in real time. The answer is Git. Git is a distributed version control system and invaluable support for any developer! It’s what allows you to create a project’s compilation history, manage versions, control progress and edit the code you create, then publish it to GitHub.
Visual Studio Code has built-in support for Git. Git is a distributed approach to version control. Git was created by Linus Torvalds in 2005 to manage the development of the Linux kernel. Simply put, Git tracks changes made to files, allowing you to revert to previous versions of files if necessary.
What do you need?¶
Git¶
Before you start using Git integration in VS Code, first make sure you have Git downloaded and configured. To verify that you have Git installed, open the integrated terminal in VS Code using the keyboard shortcut CTRL +, then type git --version. If the terminal returns git version followed by any version number, it means you actually have Git installed. If nothing is returned, you will have to(a) go to https://
Then check that Git is configured correctly by setting up your name and email address. To check if Git has already been configured, go to a terminal and run the command:
git config --global --list
If Git has been configured, the terminal will return the username and email address you set. If not, you must configure Git by doing the following:
- To set your name run:
git config --global user.name <your name> - To set your email run:
git config --global user.email <your email>
This information is required to use Git and must be entered before approving any changes. For additional information on Git configuration and initial requirements, see official Git documentation.
GitLens¶
Install the GitLens plugin inside VS Code!
With over 20 million installations, GitLens is the most popular Git extension for Visual Studio Code. It provides valuable insight into code authorship and unlocks the full power of Git inside VS Code. GitLens enhances the Git capabilities built into VS Code. Whether you’re an experienced Git developer or just starting out, GitLens makes using the full power of Git easier, safer and faster.
This GitLens tutorial will show you how to use GitLens in VS Code and get the most out of the tool. Sign up for GitLens+ to get the most out of your experience - it costs nothing.
Working with version control¶
- Log into GitHub from the GitLens plugin, introduce yourself - giving your login and email in the terminal.
- Create a test repository on GitHub (don’t forget to select the “Create Readme file” hook), connect to it directly from the GitLens plugin in VS Code. Try to make trial changes to the Readme file.
- How to work in a team? You need to grant permissions to your collaborator by going to the “Collaborators” tab on the GitHub site, under the general repository settings.