These assignments will help you get familiar with various workflows in git.
Step 0: Figure out what folder you will be doing these exercises in. If you don't know how to choose, create a folder in your Home
directory called sandbox
.
cd
into sandbox
and create a folder in there called git-practice-local
.
cd
into the directory you will be working in.- Initialize a git repository in the current directory using
git init
. This creates a hidden folder called.git
which tells your computer that this directory is a git repository. - Create a file called
README.md
. - Open the readme file with VSCode using
code .
- Write a haiku in the readme file. A haiku is a poem where the first line has 5 syllables, second has 7 syllables, and third has 5 syllables.
- Add and commit the readme file.
You now have a git repo on your computer!
This assumes you did the previous steps already.
- On
github
, create a new repository. Give it the namegit-practice-local
. DO NOT CHECK ANY OF THE BOXES - Make sure the SSH button at the top is clicked, not HTTPS.
- Follow the second set of directions that say "...or push an existing repository from the command line". Run each of those commands in the terminal, in the directory that you created during the previous exercise.
You now have a local repo that is synced to github! You can push and pull without fear.
- On
github
, create a new repository. Give it the namegit-practice-remote
. CHECK THE ADD A README FILE BOX cd
to the sandbox directory- Clone the repo to your computer
You now have a repo that is synced to github!
Note the difference between this method and the one above is just about who creates the repository first. The end result is the same (though the contents of the files might be different, you can still push and pull).
These steps will walk you through forking and making pull requests. Practice this alone!
- Fork this lesson by clicking the fork button on the top right of this page
- Clone the forked copy to your computer
cd
to the cloned directory- Create a new file called
haiku.txt
Add
andcommit
the empty text file- Write a haiku in the text file
Add
andcommit
the changesPush
your changes up to your forked copy- On
github
, go to your forked copy and make a pull request. - In the title of your pull request, put your name
- In the description of your pull request, write a nice message to your instructors
- Create the pull request
- Pray that your pull request gets accepted by the maintainers of the project
In order to complete this part of the lab you will need to work with a partner. Only 2 people in a group!
Have one person be Partner A
and another be Partner B
.
- Partner A:
- Create an empty
github
repository calledgithub-practice
. Check the README box. - Clone your newly created repository, giving you a local copy of the code on your machine.
- Send Partner B the link to your repo on github
- Partner B:
- Fork your partner's repository
- Clone the forked copy to your computer.
- Create a file called
haiku.txt
- Write a haiku inside the file
- Add and commit the changes
- Push the changes up to github
- Create a pull request on your forked copy
- Partner A:
- Accept the pull request
- Pull the latest changes down to your computer
- Create another file called
haiku2.txt
and write a haiku inside it - Add and commit the changes
- Push your code back up to github
- Partner B:
- Add Partner A's repository as a remote on your local machine. Use the clone (SSH) link, not the website address
- Pull your partner's changes to your local machine (
git pull <remotename> <branchname>
) - Revert the last commit Partner A made, undoing their haiku
- Add and commit your changes
- Push your changes up to github
- Make a pull request
- Partner A:
- Accept the pull request
- Pull the changes to your local machine. Both of you should now be looking at the same code.