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)
- Git Basics
- Git Branches
-
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
- 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:
-
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 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.
-
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 ..mkdir- do 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 init- Clone 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 commit - show how to
git addall changes, or specific files - show
git statusandgit log
- what happens after each
-
Explain what happens after
git push -
Branches (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
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-css - Add the session exercises from the previous week to the
html-css/week1folder - Create a PR (Pull Request) to your own repository, from your
html-and-cssbranch to merge changes into themainbranch - Finally, have the person on your right review this PR before you agree to merge it to
main.
Tips for this exercise:
- Use descriptive
commitmessages - Make 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 does - Merge, after the person on your right has reviewed and approved. You might need to first address any comments they might have.
- When you are on
mainbranch, of the assignment repository create a branch namedgit-week1/exercise-1/<your-name>and move to it - Create a folder named
session-playgroundin thegitfolder, under/week1 - Create the following files inside the
session-playgroundfolder:apples-file.txt,bananas-file.txt,oranges-file.txt - Add some text to each of the files
- Add and commit the
apples-file.txt - Add and commit both the
oranges-file.txtand thebananas-file.txt - Add more text to the
apples-file.txt - Add and commit the changes in the
apples-file.txt - Push 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
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 it - Create a file named
my-assignment.txtin thegitfolder, under/week1/session-playground - Add some text to the
my-assignment.txtfile - Add and commit the changes in the
my-assignment.txtfile - Add more text to the
my-assignment.txtfile - Add and commit the changes in the
my-assignment.txtfile - Push your changes to GitHub
- On GitHub, create a pull request (on your own fork) from the exercise branch to
main - On your computer add some more text to the
my-assignment.txtfile - On your computer, add and commit the changes in the
my-assignment.txtfile - Push 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.
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 it - In the
gitfolder, under/week1/session-playground, create a file namedcolors.txt - Add two colors to the file
colors.txt, one per line - Add and commit the changes in the
colors.txtfile - Push 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 changes - On your computer, add a color in the first line of the file
colors.txt, add and commit your changes - Push the branch
git-exercise-4to GitHub. Discuss what is happening and how to solve it.
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 it - In the
gitfolder, under/week1/session-playground, create a file namedmovies.txt - Add two movie names to the file
movies.txt, one per line - Add and commit the changes in the
movies.txtfile - Push 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.
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-exercise - Using the command line go to that folder and create a new repository there (
git init) - Create a new file in that folder called
countries.txt - Add two country names (one per line) to the
countries.txtfile - Commit your changes
- Create a new branch named
add-countries, move to that branch - Add two more country names (one per line) to the
countries.txtfile - Commit your changes
- Go back to
main - Create a new branch named
add-cities, move to that branch - Create a new file named
cities.txt - Add two city names (one per line) to the
cities.txtfile - Commit 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
main - Merge 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?
- 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