Introduction to Git and GitHub
Learn the basics of using Git and GitHub for version control and collaboration. Git is a widely used version control software that tracks changes to a group of files, referred to as a repository. GitHub is a popular website for hosting and sharing Git repositories, making it easier to collaborate and share your work. Together, Git and GitHub provide a platform that is increasingly used for collaboration in research and academic environments.
In this beginner workshop, participants will learn key concepts, create their own Git repository, and publish to GitHub. No previous experience with Git is required. Familiarity with the command line interface will be helpful but is not necessary.
Pre-workshop setup
Please make sure to have a Bash Shell and Git installed before the workshop.
If you do not have access to a laptop or have difficulty meeting these prerequisites please contact shayanfa@mail.ubc.ca. We will do our best to ensure everyone can participate.
1. Create a free GitHub account
2. Install the Bash Shell and Git
- Mac and Linux. Bash is already installed.
- Install Git using these instructions.
- If you use macOS Catalina or newer versions, change the default shell to Bash by running the following command:
$ chsh -s /bin/bash
- Windows. For the easiest pathway on Windows, follow these instructions to download the Bash Shell and Git at the same time (a Video Tutorial is also available).
- Download the Git for Windows installer.
- Run the installer and follow the steps below:
- Click on “Next” four times (two times if you’ve previously installed Git). You don’t need to change anything in the Information, location, components, and start menu screens.
- From the dropdown menu select “Use the nano editor by default” and click on “Next”.
- Ensure that “Git from the command line and also from 3rd-party software” is selected and click on “Next”. (If you don’t do this Git Bash will not work properly, requiring you to remove the Git Bash installation, re-run the installer and to select the “Git from the command line and also from 3rd-party software” option.)
- Ensure that “Use the native Windows Secure Channel library” is selected and click on “Next”.
- Ensure that “Checkout Windows-style, commit Unix-style line endings” is selected and click on “Next”.
- Ensure that “Use Windows’ default console window” is selected and click on “Next”.
- Ensure that “Enable file system caching” and “Enable Git Credential Manager” are selected and click on “Next”.
- Click “Install”.
- Click “Finish”.
- If your “HOME” environment variable is not set (or you don’t know what this is):
- Open command prompt (Open Start Menu then type
cmd
and press “Enter” - Type the following line into the command prompt window exactly as shown:
setx HOME "%USERPROFILE%"
- Press “Enter.” you should see
SUCCESS: Specified value was saved.
- Quit the Command Prompt by typing
exit
then pressing “Enter”
- Open command prompt (Open Start Menu then type
This will provide you with both Git and Bash in the Git Bash program.
Another option on Windows is activating Windows Subsystem for Linux (WSL). WSL is a compatibility layer to run Linux binary files natively on Windows 10. Please follow this guide to activate WSL on your system.
To install WSL on your Windows Machine, use the Simplified install.
3. Configure Git user name and email
Open Bash (Terminal in Mac, Git Bash in Windows) and enter the following commands to configure Git. (Note that $
represents the command prompt; the commands themselves start with the word git
.)
$ git config --global user.name "Your Name"
$ git config --global user.email "your@email"
This is only required once. Your user name and email will be recorded with each change you make to documents tracked with Git. The email address should be the same one you used when setting up your GitHub account. You can find all the other existing configurations of git on your local machine by running git config --list
4. (OPTIONAL) Set your preferred text editor
Git sometimes opens a text editor automatically so you can complete a task. The Git default is the Vi/Vim text editor, which some users may find difficult to use. To change the default text editor run the command below and indicate your preferred editor. This can be any text editor, but common choices are "notepad"
on Windows and "nano"
on Mac or Linux.
$ git config --global core.editor "notepad"