Session Plan
Session materials
These are some examples of previously created materials by mentors that you can use yourself, or for inspiration.
Introduction to Git (by @aina21, Team 31)
Session outline
What is version control?
Version control is like a super-organized notebook that keeps a history of all the changes made to your project folders and files. It lets you:
Go back to older versions if something goes wrong
See who made each change
Work with others without overwriting each other’s work
Google docs demonstration
Git - the most popular version control system
Git is a version control system, widely used by software developers (and not only). Think of it as a smart time machine for your files—especially code or text documents.
Save a snapshot of your project (called a commit) at any point
Compare changes between versions
Work together with other people and combine everyone’s work smoothly
Experiment with new ideas safely, without messing up the main project
Git vs. GitHub (Slide 3 from Git-basics.pdf)
Git
Version control software on your computer
Works offline (no need for internet)
Command-Line Interface based, but has various graphical interface alternatives as GitHub Desktop, GitKraken, SourceTree
GitHub
Website that hosts Git repositories in the cloud
Web interface for viewing code and changes
Collaboration tools (pull requests, projects, issues, comments)
Enabled social coding (followers, stars, forks, use profiles)
Install Git if not done already
Configure Git
git config --global user.name "name"git config --global user.email "email"git config --global core.editor "code -w"(without-wthe commit is aborted with empty message)
Command line basics
pwd, and explain how paths worklscdcd ..mkdirdo a little exercise
What is a repository and how to create one (Slide 4, Git-basics.pdf)
kind of a folder, but not all files in the folder have to be in the repository
git initClone an existing repository
Golden rule:
ALWAYS make sure you are not inside a git repository when you create a new one. You can check by typing
git statusin your Terminal. If you get an error it means you are not inside a git repository and you can safely create a new one.
The commit (Slide 7, Git-basics.pdf)
a snapshot of the entire repository
who made the changes
when the changes were made
a message describing the changes in the commit
Demonstration to making a commit
what happens after each
git addandgit commitshow how to
git addall changes, or specific filesshow
git statusandgit log
Explain what happens after
git pushBranches (Exercise 2, Git-branches.pdf)
Create a branch
Make a commit
push changes to remote
Pull Requests
Create a pull request
Reviewing a pull request (commenting, approving, requesting changes)
Merging a pull request
Updating local
main
Forks
Your "copy" of a source repository
How forks are useful for collaboration
Useful VS Code extensions
GitLens - Git supercharged
GitHub Pull Requests
Exercise 1
Objective: The goal is to set up your assignment repository fork and create your first PR (Pull Request).
[!NOTE] You will use this repository to hand in your assignments during the entire HackYourFuture program.
Create a repository fork on your GitHub and clone it locally, following the instructions from HackYourFuture-CPH/hyf-assignment-template
Check out to a new branch called
html-and-cssAdd the session exercises from the previous week to the
html-css/week1folderCreate a PR (Pull Request) to your own repository, from your
html-and-cssbranch to merge changes into themainbranchFinally, have the person on your right review this PR before you agree to merge it to
main.
Tips for this exercise:
Use descriptive
commitmessagesMake a commit for each folder/exercise you add (makes it easier to track changes/updates)
Switch between the Terminal and GitHub on each
commitandpushto learn better what each command exactly doesMerge, after the person on your right has reviewed and approved. You might need to first address any comments they might have.
Exercise 2
When you are on
mainbranch, of the assignment repository create a branch namedgit-week1/exercise-1/<your-name>and move to itCreate a folder named
session-playgroundin thegitfolder, under/week1Create the following files inside the
session-playgroundfolder:apples-file.txt,bananas-file.txt,oranges-file.txtAdd some text to each of the files
Add and commit the
apples-file.txtAdd and commit both the
oranges-file.txtand thebananas-file.txtAdd more text to the
apples-file.txtAdd and commit the changes in the
apples-file.txtPush your changes to GitHub
Go to the branch on GitHub and look at the commits, analyze and discuss how it looks and how it connects with what you just did
Exercise 3
Objective: The goal of this exercise is to practice the assignment workflow.
When you are on
mainbranch, create a branch namedgit-week1/exercise-3/<your-name>and move to itCreate a file named
my-assignment.txtin thegitfolder, under/week1/session-playgroundAdd some text to the
my-assignment.txtfileAdd and commit the changes in the
my-assignment.txtfileAdd more text to the
my-assignment.txtfileAdd and commit the changes in the
my-assignment.txtfilePush your changes to GitHub
On GitHub, create a pull request (on your own fork) from the exercise branch to
mainOn your computer add some more text to the
my-assignment.txtfileOn your computer, add and commit the changes in the
my-assignment.txtfilePush the changes to GitHub
On GitHub, check what happened to the pull request you created in step 8.
Merge the pull request.
Locally, go to the
mainbranch and updatemainby "downloading" the new commits from GitHub:git pull origin main.
Exercise 4
Objective: Face your first Git error and try to find a solution online on your own.
On your assignment repository go to the branch
main, create a branchgit-week1/exercise-4/<your-name>and move to itIn the
gitfolder, under/week1/session-playground, create a file namedcolors.txtAdd two colors to the file
colors.txt, one per lineAdd and commit the changes in the
colors.txtfilePush the branch
git-exercise-4to GitHub.On GitHub, go to the branch
git-exercise-4and add a color in the last line of the filecolors.txt, commit your changesOn your computer, add a color in the first line of the file
colors.txt, add and commit your changesPush the branch
git-exercise-4to GitHub. Discuss what is happening and how to solve it.
Exercise 5
Objective: Learn to handle a common mistake of forgetting to checkout to the right branch, when already having a few commits pushed.
On your assignment repository DON'T go to the main branch, make sure to stay on the branch from the previous exercise.
Create a branch
git/week1/exercise-5/<your-name>and move to itIn the
gitfolder, under/week1/session-playground, create a file namedmovies.txtAdd two movie names to the file
movies.txt, one per lineAdd and commit the changes in the
movies.txtfilePush the branch
git-exercise-5to GitHub.On GitHub, create a pull request from your new branch to
main.See what commits you have there - do you only have commits from this exercise? Do you have commits that should not be here? Discuss why it happened and how to solve this situation.
Exercise 6: Into the deeps
Objective: Get comfortable with branching. Take notes of the answers to the questions in points 14, 15, 16, 17, 18, 19, 22, 23, 25, and 26. Discuss the answers in pairs.
Create a new folder in your Desktop called
branch-exerciseUsing the command line go to that folder and create a new repository there (
git init)Create a new file in that folder called
countries.txtAdd two country names (one per line) to the
countries.txtfileCommit your changes
Create a new branch named
add-countries, move to that branchAdd two more country names (one per line) to the
countries.txtfileCommit your changes
Go back to
mainCreate a new branch named
add-cities, move to that branchCreate a new file named
cities.txtAdd two city names (one per line) to the
cities.txtfileCommit your changes
Go back to
mainand take a look around your folder. Which files do you see? What are their contents?Do
git log --oneline. Which commits do you see?Go to the
add-countriesbranch and take a look around your folder. Which files do you see? What are their contents?Do
git log --oneline. Which commits do you see?Go to the
add-citiesbranch and again take a look around your folder. Which files do you see? What are their contents?Do git
log --oneline. Which commits do you see?Now go to
mainMerge the branch
add-countrieswith main (git merge add-countries)Take a look at your folder, which files do you see? What are their contents?
Do
git log --oneline. Which commits do you see?Now merge the branch
add-citieswith main (git merge add-cities)Take a look at your folder, which files do you see? What are their contents?
Do
git log --oneline. Which commits do you see?
Other material and links
Cheat-sheet - sheet of the commands used during the session
Git Basics - the slides used to teach some concepts during the session.
Learn Git Branching - interactive website for... learning Git branching
Oh My Git - open source game for learning everything Git
Last updated