In this exercise you will get some practice submitting your homework by pushing it to Github and then creating a pull request. You will be using this workflow every week to submit your homeworks, so it's important that you get comfortable with it. You will also practice adding/commiting files one by one.
You will use the your class homework repository on your computer to do the exercise. Here are the instructions:
- Go to your class homework repo on your computer (you would have already cloned it in preparation or in class exercises)
- Go to branch
main
- Pull the latest changes to make sure your local
main
is up to date - Create a branch for your homework, named
git-week1/yourname
, and move to that branch - Inside the folder
git/week1
create 3 new files:- a file named
my_favorite_food.txt
, inside the file write your favorite food recipe (you can just find a random recipe on google and paste it in the file ;) - a file named
my_second_favorite_food.txt
, inside the file write the recipe for your second favorite food - a file named
countries.txt
, where you list three countries that you have visited (this doesn't need to be true, you can just write the names of three random countries)
- a file named
- Add and commit the file
my_favorite_food.txt
; - Add and commit the file
my_second_favorite_food.txt
; - Add and commit the file
countries.txt
; - Push your changes into your class homework repository on Github.
- Go to Github and create a pull request (PR) from the branch
git-week1/yourname
tomain
You have hopefully recieved a review on your last week html-css homework. If you submitted it later into the week, you might not have a review yet, in that case - wait. Be faster next time :). If you submitted the homework too late, you are not entitled to a review, but you can still try and ask for one.
- go to your local copy of the class homework repo,
main
branch; - update the
main
branch with the latest changes in the origin; - checkout to your
html-css
homework branch; - merge
main
into this branch; - make changes to your
html-css
homework as adviced by mentors in your homework review and/or make any other changes or improvements; - commit and push the changes to the branch in origin;
- close the
html-css
homework PR.
Commands that you will need:
git branch <branch-name>
- to create a new branch named<branch-name>
git checkout <branch-name>
- to move to a branch named<branch-name>
git add <file_name>
- tell git to start tracking a file and to update what will be commitedgit commit -m "commit_message"
- commit (save) your changesgit push origin <branch-name>
- push (upload) your changes in your current branch to your github repository into the branch named<branch-name>
.
Note
For the sake of consistency (and to avoid mistakes), make sure that when you push you do it to a branch with the same name as the branch where you are, e.g. if you are on a branch named git-week1
then push to a branch named git-week1
by typing git push origin git-week1
.
When pulling, if you want to pull from a branch named, for instance main
, make sure that you are in a branch with the same name (main
) on your computer as well, and only then do git pull origin <branch-name>
.
Other useful git commands:
git status
- remember, it is your best friend, it tells you what is the state of your repository and sometimes what you should do.git branch
- this is your second best friend, it tells you in which branch you are (you can also see where you are when you dogit status
)git log
git log --oneline
git pull origin <branch-name>
- pull (download) your changes from your github repository in the branch named<branch-name>
, into your current local branch.
Command line commands that might be useful:
pwd
- print working directory, to know where you arecd <folder_name>
- to go inside a folder named<folder_name>
cd ..
- to go to the parent folder of your current foldermkdir <folder_name>
- to create a new folderls
- list all the folder contentsls .*
- list all the folder contents, also invisible folders/files (e.g. the git folder)