Github for beginners
Author
These exercises where authored and tested by Kasper Thystrup Karstensen
Assignment
Part 1: First time setup, first repository, and Github calibration
Introduction
This assignment is designed to guide you through the process of setting up a new repository, connecting it to Github, and configuring your local Git environment.
Task
- On your Unix terminal, set up your user email to match the one you created a GitHub account with, using
git config --global user.email "YOUR_GitHub@E.MAIL"
.
- Set up the authorship name (called user.name in git terminology), this name will be visible in the log files on your local and online repository. Use
git config --global user.name "YOUR AUTHOR NAME"
.
- Navigate to the folder where you want to keep your repository on your machine. Let’s say you want to keep them in a folder called repo located at your home directory, yet the directory does not yet exist. First make the folder using
mkdir ~/repo
and then go into the new foldercd ~/repo
- Log into your Github account and create a new empty repository. Provide a meaningful name (E.g. my_first_repository). Consider to make it public as it would not require login information whenever you push changes to the repository from your local machine → You can always delete the repository when this exercise is done!.
- Make sure to check the Add a README file then click Create repository.

- Click the Code button, select the SSH pane, and copy paste the box contents by clicking on the icon next to the address., By now, the repository page should look something along the lines of this:

- Head back to your Unix terminal, from the
~/repo
folder, pull the repository down to your local machine:git pull ADDRESS
Where you replaceADDRESS
with the copied link. e.g. git@github.com:GitHubUserName/my_first_repository.git
Part 2: Adding your scripts to the repository
Introduction
This assignment is designed to guide you through the process of adding your scripts to your newly created repository, and making sure they are properly tracked using Git.
Task
- In your Unix terminal, Generate a decoy file (empty file) in the repository using:
touch awesome_script.py
.
- Check the status of your repository with
git status
.
- Stage the latest changes (the empty file) using
git add awesome_script.py
andgit commit
. Be sure to put in a helpful title and perhaps a detailed description.
- Push the local changes to Github using
git push origin main
.
- Inspect your repository on Github to ensure that it matches your local repository (remember to refresh the page after pushing).
- Head back to the Unix terminal (make sure you are still at the repository folder → e.g.
~/repo/my_first_repository
and create a script folder inside the repository folder (mkdir script
), then copy the empty file into the script folder.
- Edit the README.md file and write some random description in the file. Make sure to save the file before exiting.
- Check the latest detected changes using
git status
. You can see that the README and the script folder are untracked.
- Add the scripts folder and README.md file to the repository and commit.
Part 3: Managing multiple versions with branching
Introduction
This assignment is designed to guide you through the process of branching, a key concept in Git that allows you to work on different versions of your code in parallel.
Task
- Check existing branches using
git branch
.
- Generate a new branch (recommended name: dev) using
git switch --create dev
.
- As branching can be a bit difficult to keep a grasp on, grab a paper, draw a line labelled
main
, and draw a parallel branch from somewhere in the line and label it with the branch name (e.g., dev).
- Make another decoy script inside the script folder
touch script/another_awesome_script.sh
.
- Read the output of a
git status
command and make sure you are at the correct branch (dev
).
- Do a
git add script/
and commit changes this time usinggit commit -m "Added another awesome script" -m "This script can actually save the world, by spreading complete awesomeness over the entire metaverse - by shutting it down..."
. What do you think the two-m
arguments does?
- Inspect the commits history by doing a
git log --graph
(--graph
is an optional argument). Are there the expected amount of commits?
- Head back to the main branch, first by doing a
git switch main
and then following with a checkup:git status
- Check the contents of the script folder
ls script/
. How many files are there now?
- Push the new branch (dev) to your remote Github repository using
git push origin dev
.
- On Github, navigate over to the dev branch and confirm that your changes have indeed been pushed.
Part 4: Bringing it all together with merge
Introduction
This assignment is designed to guide you through the process of merging different branches together.
Task
- To merge the latest changes, change position to the branch which will ingest the target branch, in this case
main
will ingest the contents ofdev
. Usegit switch main
.
- Check the current status prior to merging
git log --graph
.
- Now merge the feature branch into the development branch using
git merge dev
.
- Rerun the above log command and inspect the output.
- Normally, this would be a good time to delete the branch, which just got ingested, using a
git branch -d BRANCH_NAME
. However in this case, we will do an exception, as thedev
branch are continously being used to push new development, even unstable ones. Instead of deleting the dev branch, lets just push everything.git push origin main dev
- Inspect the results on GitHub.
Resolving conflicts
While you shouldn’t experience conflicts in this exercise. However, if you were to fill out the another_awesome_script.sh
and awesome_script.py
files with text, shifting back and forth between branches, could introduce conflicts. That is, you have made different changes to a specific section, which git requires help to resolve, if that where the case, the below guide is made to aid in resolving such conflicts.
Task
- For each conflicting file
- Open the conflicting file.
- Inspect <<<<<HEAD (current version at master).
- Inspect the ====== … >>>>>>>dev (the target version that is attempted to merge into master).
- Decide whether the HEAD or the dev contains the correct text
- Remove the wrong / outdated text alongside with the >>>, ===, <<<, HEAD, and dev sections.
- Add the conflicting files to your repository with
git add
and commit the changes withgit commit
.