We will use the homework repository and the branch main
.
It will be your own individual repository or the central homework repository of your class - depending on which approach you are using in your class.
- clone the homework repository into your computer.
- when you are on
main
branch, create a branch namedgit-week1/exercise_1/<yourname>
* and move to it; - create a folder named
class_playground
in thegit
folder, under/week1
; - create the following files inside the
class_playground
folder: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.txt
and 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.
*
<yourname>
should be replace by your actual name, f.x. git/week1/exercise_1/maria
The goal of this exercise is to practice the homework workflow. It will basically follow the second part of the class videos.
- when you are on
main
branch, create a branch namedgit-week1/exercise_2/<yourname>
* and move to it; - create a file named
my_homework.txt
in thegit
folder, under/week1/class_playground
; - add some text to the
my_homework.txt
file; - add and commit the changes in the
my_homework.txt
file; - add more text to the
my_homework.txt
file; - add and commit the changes in the
my_homework.txt
file; - push your changes to github;
- on github, create a pull request from the exercis branch to
main
; - on your computer add some more text to the
my_homework.txt
file; - on your computer, add and commit the changes in the
my_homework.txt
file; - push the changes to github;
- on github, check what happened to the pull request you created in step 8.
- if you are on an individual homework repository approach, merge the PR and proceed to the next step. If you are on a central homework repository approach, DO NOT merge the PR, and skip the next step.
- go to the
main
branch and updatemain
by "downloading" the new commits from github:git pull origin main
.
*
<yourname>
should be replace by your actual name, f.x. git/week1/exercise_2/maria
In this exercise, you will get an error when pushing to github and you will have to solve it.
- on your homework repo go to the branch
main
, create a branchgit-week1/exercise_3/<yourname>
* and move to it; - in the
git
folder, under/week1/class_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.txt
file; - push the branch
git_exercise_3
to github. - on github, go to the branch
git_exercise_3
and 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_3
to github. Discuss what is happening and how to solve it.
*
<yourname>
should be replace by your actual name, f.x. git/week1/exercise_3/maria
In this exercise you will get in trouble by checking out from the wrong branch you will have to solve it.
- on your homework repo DON'T go to the main branch, make sure to stay on the branch from the previous exercise.
- create a branch
git/week1/exercise_4/<yourname>
* and move to it; - in the
git
folder, under/week1/class_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.txt
file; - push the branch
git_exercise_4
to 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.
*
<yourname>
should be replace by your actual name, f.x. git/week1/exercise_4/maria
The goal of this exercise is to get more familiar with branches.
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 your breakout room.
- 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.txt
file; - 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.txt
file; - 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.txt
file; - commit your changes;
- go back to
main
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_countries
branch 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_cities
branch 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_countries
with 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_cities
with 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?