Tutorial 9 - GitHub¶
Overview¶
Git is a distributed version control system (VCS) that allows developers to track changes in their code over time. It was created by Linus Torvalds in 2005 and is widely used for managing source code for software projects. Git enables multiple developers to work on a project simultaneously and independently, and it tracks changes made by each contributor. It provides features such as branching, merging, and history tracking.
With Git, each developer has a local copy of the entire project history. Developers can work offline, commit changes locally, and then synchronize with a central repository later.
Key features of Git include:
Manage projects with repositories.
Clone a project to work on a local copy.
Control and track changes with staging and committing.
Branch and merge for working on different parts and versions of a project.
Push local updates to the main project.
A repository is typically used to organize a single project. Repositories can contain folders and files, images, videos, spreadsheets, and data sets. Repositories typically include a README file that provides information about the project. README files are written in plain text Markdown language.
GitHub is a web-based platform that provides hosting for Git repositories. It offers a graphical interface for managing Git repositories, collaboration features, and additional tools for project management.
Key features of GitHub are:
Repository hosting: GitHub provides a place to store and manage Git repositories.
Collaboration: Developers can collaborate on projects by forking repositories, making changes, and submitting pull requests.
Issue tracking: GitHub includes an issue-tracking system for managing bugs, feature requests, and other tasks.
Pull requests: Developers can propose changes to a project by submitting pull requests, which can be reviewed and merged by project maintainers.
Web-based interface: GitHub provides a user-friendly web interface for interacting with Git repositories.
To summarize, Git serves as the version control system enabling developers to monitor code changes, whereas GitHub functions as a web-based platform offering hosting for Git repositories along with extra collaboration tools.
Working with GitHub¶
Sign up for a GitHub account using the following link.
To create a new repository on GitHub, click on the “New repository” button shown below in the upper right corner. Then, fill in the relevant details. You can set the repository as “Public” or “Private”. You also have options to add a README file, or choose a license for your repository. Click the “Create repository” button to finish the creation process.


Making and Committing Changes¶
We can make and save changes to the files in a GitHub repository via commits. Each commit has an associated commit message, which is a description explaining why a particular change was made. Commit messages capture the history of the changes, so that other contributors can understand what you have done and why.
For instance, to edit the README.md file, we can follow these steps:
Click on the “Edit file” (pencil) button located in the upper right corner.
In the editor, write some text to describe the repository.
Click “Commit changes…”.
In the “Commit message” field, write a message title and a brief description of the changes.
Click “Commit changes”.
Creating a Branch¶
By default, a repository comes with a primary branch called main, which serves as the authoritative branch. We have the option to establish additional branches stemming from the main branch within the repository. The creation of branches allows for the simultaneous existence of various versions of a project. This proves beneficial when incorporating new features into a project without altering the primary source code. Changes made in different branches remain isolated from the main branch
until a later stage when merging is addressed. Branches provide a space for experimentation and editing before finalizing changes and committing them to the main branch.
When branching off the main branch, we essentially create a duplicate or snapshot of the main branch as it existed at that specific moment. If someone else modifies the main branch while you are developing your branch, you have the option to incorporate those updates.
To create a new branch:
Click the dropdown menu beside the
mainbranch.Type in a descriptive name in the field “Find or create a branch …” shown below, for example called
test2.Click on “Create branchtest2** from main”**.
Now there are two branches, main and test2 that are exactly the same.

Opening a Pull Request¶
An example of a flow diagram for making changes to a branch is depicted in the next figure, showing the 'main' branch, a new branch called 'feature', and the path of the 'feature' branch before it is merged into the 'main' branch.

Pull requests are the main form of collaboration on GitHub. When you open a pull request, you are proposing your changes to the repository, and requesting that someone review and pull in your contribution and merge them into their branch.
You can open a pull request and start a discussion as soon as you make changes to your branch, even before the code is finished. By using GitHub’s @mention feature in the pull request message, you can ask for feedback from specific people or teams, regardless of whether they are down the hall or 10 time zones away.
Pull requests show the differences (short: diffs) in the content from both branches. The changes, additions, and subtractions between the branches are shown in different colors.
Let’s apply changes to the test2 branch, and create a pull request:
Click the “Pull requests” tab in the top menu of the repository.
Click on the “New pull request” button.
In the “Compare changes” box, select the new branch with changes that you made to compare with the main branch. For instance, select the base branch
mainand compare it with thetest2branch.Look over your changes in the diffs on the “Comparing changes” page, and make sure they are what you want to submit.
Click “Create pull request”.
Give your pull request a title and write a brief description of your changes. Optionally, to the right click the button next to Reviewers, Assignees, Labels, Projects, or Milestone to add any of these options to your pull request. These options are optional, but they provide additional ways to organize and collaborate on pull requests.
Click “Create pull request”.
Merging a Pull Request¶
When you merge your pull request, the changes on your branch will be incorporated into main. Sometimes, a pull request may introduce changes to code that conflict with the existing code on the main branch. If there are any conflicts, GitHub will alert you about the conflicting code and prevent merging until the conflicts are resolved. You can make a commit that resolves the conflicts or use comments in the pull request to discuss the conflicts with your team members.
To merge your branch into the main branch:
At the bottom of the pull request, click “Merge pull request” to merge the changes into main.
Click “Confirm merge”. You will receive a message that the request was successfully merged and the request was closed.
Now that your pull request is merged and your changes are on main, you can safely delete the branch with the edits by clicking on the “Delete branch” button in the merging pull request message.
If you need to make further changes, simply create a new branch and repeat the same workflow.
Working with a Local Git Repository¶
This section explains how to use Git from the command line interface (CLI) to download a GitHub repository to our computer, make local changes, and then upload those changes back to GitHub.
Download and install Git from link.
After installation, open Command Prompt, Terminal, or Git Bash. The preferred shell is Git Bash, which comes installed with Git for Windows. It is a Unix-style shell that emulates a Linux terminal.
Configure your Git identity by providing your GitHub username and email address. This is done only once when you begin using Git.
git config --global user.name "username"
git config --global user.email "youremailaddress@example.com"
Verify your settings.
git config --list
Clone an existing repository from GitHub. Go to the repository’s GitHub page (e.g., Hello World repository that we created above), and copy the URL (
https://github.com/avakanski/hello-world). Run the following command in Git Bash, to download the repository to your home directory.
git clone https://github.com/avakanski/hello-world.git
Then move into your local project folder.
cd hello-world
Make local changes to the files. For instance, we can edit the README file using VS Code, and save the file.
Stage (prepare) the changes for commit. The
.(dot) indicates to add files in the current directory.
git add .
Commit your changes and include a descriptive message.
git commit -m "Changed the README file"
Check repository status, to see which files have changed.
git status
Pull the latest changes from the remote branch on GitHub (recommended step), to make sure your local repository is up-to-date with GitHub. By default, Git assigns the name
originto the remote repository on GitHub, and the namemainto the local changes.
git pull origin main
Push your changes to GitHub. This code uploads your local commits to the GitHub repository.
git push origin main
Verify your changes at the repository page on GitHub. Your updates should now appear online.
Working with a New Branch¶
The following commands provide a similar example where the changes are made in a separate branch, which is afterward merged with the main branch.
Create a new branch called
test3.
git checkout -b test3
Make changes to the local files (e.g., using the VS Code or a Python editor). Afterward, stage and commit the changes.
git add .
git commit -m "Add a new branch test3"
Push the new local branch
test3to the remote repository on GitHub.
git push origin test3
After pushing, if you open the repository on GitHub, you will see the new branch test3 listed and available to other users in the project.
Merge the new branch
test3into themainbranch.
First, switch back to the main branch.
git checkout main
Then merge and push the changes.
git merge test3
git push
Alternatively, you can open a Pull request on GitHub to merge the new branch test3 into main.
References¶
Hello world. GitHub Docs. (n.d.). https://docs.github.com/en/get-started/quickstart/hello-world
F., Campion. An intro to Git and GitHub for beginners (tutorial). HubSpot Careers. https://product.hubspot.com/blog/git-and-github-tutorial-for-beginners
Ajibola.Segunemmanuel. (2022, September 27). How to use Git and GitHub – Introduction for Beginners. freeCodeCamp.org. https://www.freecodecamp.org/news/introduction-to-git-and-github/
Git tutorial. (n.d.). https://www.w3schools.com/git/
BACK TO TOP