|
| 1 | +# Class exercises |
| 2 | + |
| 3 | +## Exercise 1 |
| 4 | + |
| 5 | +We will use the homework repository and the branch `main`. |
| 6 | + |
| 7 | +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. |
| 8 | + |
| 9 | +1. clone the homework repository into your computer. |
| 10 | +2. when you are on `main` branch, create a branch named `git-week1/exercise_1/<yourname>`\* and move to it; |
| 11 | +3. create a folder named `class_playground` in the `git` folder, under `/week1`; |
| 12 | +4. create the following files inside the `class_playground` folder: `apples_file.txt`, `bananas_file.txt`, `oranges_file.txt`; |
| 13 | +5. add some text to each of the files; |
| 14 | +6. add and commit the `apples_file.txt`; |
| 15 | +7. add and commit both the `oranges_file.txt` and the `bananas_file.txt`; |
| 16 | +8. add more text to the `apples_file.txt`; |
| 17 | +9. add and commit the changes in the `apples_file.txt`; |
| 18 | +10. push your changes to Github. |
| 19 | +11. 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. |
| 20 | + |
| 21 | +`*` `<yourname>` should be replace by your actual name, f.x. `git/week1/exercise_1/maria` |
| 22 | + |
| 23 | +## Exercise 2 |
| 24 | + |
| 25 | +The goal of this exercise is to practice the homework workflow. |
| 26 | +It will basically follow the second part of the class videos. |
| 27 | + |
| 28 | +1. when you are on `main` branch, create a branch named `git-week1/exercise_2/<yourname>`\* and move to it; |
| 29 | +2. create a file named `my_homework.txt` in the `git` folder, under `/week1/class_playground`; |
| 30 | +3. add some text to the `my_homework.txt` file; |
| 31 | +4. add and commit the changes in the `my_homework.txt` file; |
| 32 | +5. add more text to the `my_homework.txt` file; |
| 33 | +6. add and commit the changes in the `my_homework.txt` file; |
| 34 | +7. push your changes to github; |
| 35 | +8. on github, create a pull request from the exercis branch to `main`; |
| 36 | +9. on your computer add some more text to the `my_homework.txt` file; |
| 37 | +10. on your computer, add and commit the changes in the `my_homework.txt` file; |
| 38 | +11. push the changes to github; |
| 39 | +12. on github, check what happened to the pull request you created in step 8. |
| 40 | +13. 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. |
| 41 | +14. go to the `main` branch and update `main` by "downloading" the new commits from github: `git pull origin main`. |
| 42 | + |
| 43 | +`*` `<yourname>` should be replace by your actual name, f.x. `git/week1/exercise_2/maria` |
| 44 | + |
| 45 | +## Exercise 3 |
| 46 | + |
| 47 | +In this exercise, you will get an error when pushing to github and you will have to solve it. |
| 48 | + |
| 49 | +1. on your homework repo go to the branch `main`, create a branch `git-week1/exercise_3/<yourname>`\* and move to it; |
| 50 | +2. in the `git` folder, under `/week1/class_playground`, create a file named `colors.txt`; |
| 51 | +3. add two colors to the file `colors.txt`, one per line; |
| 52 | +4. add and commit the changes in the `colors.txt` file; |
| 53 | +5. push the branch `git_exercise_3` to github. |
| 54 | +6. **on github**, go to the branch `git_exercise_3` and add a color in the last line of the file `colors.txt`, commit your changes; |
| 55 | +7. **on your computer**, add a color in the first line of the file `colors.txt`, add and commit your changes; |
| 56 | +8. push the branch `git_exercise_3` to github. Discuss what is happening and how to solve it. |
| 57 | + |
| 58 | +`*` `<yourname>` should be replace by your actual name, f.x. `git/week1/exercise_3/maria` |
| 59 | + |
| 60 | +## Exercise 4 |
| 61 | + |
| 62 | +In this exercise you will get in trouble by checking out from the wrong branch you will have to solve it. |
| 63 | + |
| 64 | +1. on your homework repo **DON'T** go to the main branch, make sure to stay on the branch from the previous exercise. |
| 65 | +2. create a branch `git/week1/exercise_4/<yourname>`\* and move to it; |
| 66 | +3. in the `git` folder, under `/week1/class_playground`, create a file named `movies.txt`; |
| 67 | +4. add two movie names to the file `movies.txt`, one per line; |
| 68 | +5. add and commit the changes in the `movies.txt` file; |
| 69 | +6. push the branch `git_exercise_4` to github. |
| 70 | +7. on github, create a pull request from your new branch to `main`. |
| 71 | +8. 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. |
| 72 | + |
| 73 | +`*` `<yourname>` should be replace by your actual name, f.x. `git/week1/exercise_4/maria` |
| 74 | + |
| 75 | +## Exercise 5 |
| 76 | + |
| 77 | +The goal of this exercise is to get more familiar with branches. |
| 78 | + |
| 79 | +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. |
| 80 | + |
| 81 | +1. create a new folder in your Desktop called `branch_exercise`; |
| 82 | +2. using the command line go to that folder and create a new repository there (`git init`); |
| 83 | +3. create a new file in that folder called `countries.txt`; |
| 84 | +4. add two country names (one per line) to the `countries.txt` file; |
| 85 | +5. commit your changes; |
| 86 | +6. create a new branch named `add_countries`, move to that branch; |
| 87 | +7. add two more country names (one per line) to the `countries.txt` file; |
| 88 | +8. commit your changes; |
| 89 | +9. go back to `main`; |
| 90 | +10. create a new branch named `add_cities`, move to that branch; |
| 91 | +11. create a new file named `cities.txt`; |
| 92 | +12. add two city names (one per line) to the `cities.txt` file; |
| 93 | +13. commit your changes; |
| 94 | +14. go back to `main` and take a look around your folder. Which files do you see? What are their contents? |
| 95 | +15. do `git log --oneline`. Which commits do you see? |
| 96 | +16. go to the `add_countries` branch and take a look around your folder. Which files do you see? What are their contents? |
| 97 | +17. do `git log --oneline`. Which commits do you see? |
| 98 | +18. go to the `add_cities` branch and again take a look around your folder. Which files do you see? What are their contents? |
| 99 | +19. do git `log --oneline`. Which commits do you see? |
| 100 | +20. now go to `main`; |
| 101 | +21. merge the branch `add_countries` with main (`git merge add_countries`); |
| 102 | +22. take a look at your folder, which files do you see? What are their contents? |
| 103 | +23. do `git log --oneline`. Which commits do you see? |
| 104 | +24. now merge the branch `add_cities` with main (`git merge add_cities`) |
| 105 | +25. take a look at your folder, which files do you see? What are their contents? |
| 106 | +26. do `git log --oneline`. Which commits do you see? |
0 commit comments