You will be practicing git and git branching today.
Git is a powerful tool to keep track of changes to your files over time. You can go back and forth in time, and you can see what you did.
GitHub is a company that specializes in storing git repositories in the cloud and allowing people to share them.
Git branches are a way to protect your code while you are working on features. Until your code is ready, your changes can be in a branch so that it doesn't break master code, which might be actively used in production. It also allows multiple people to work on code at the same time, each on their own branch.
Git Knock Knock is designed to give you practice in using basic git commands and branches.
You will be using git to tell knock knock jokes to each other. Until your partner has merged their changes into master, pushed it up to GitHub, and you have pulled the changes down, you will not see the next line of the joke.
- Form a pair.
- Your partner should be in another room. Use slack to communicate.
- Each person will choose one knock knock joke.
- Decide which partner tells the joke first.
- One person forks the repository and adds the other player as a collaborator. (Go to settings, the Collaborator tab, and search by username)
- Both people clone the repo in Cloud 9.
Now that set up is done, each person will tell their joke to their partner, line by line. When it is your turn, follow these steps.
- Pull the master branch down from GitHub to get any changes your partner made.
- Cut a new branch (use a different name every time).
- If you are writing the first line of the joke, create a new file.
- Add the next line of the joke.
- Save the file.
- Add your changes to staging.
- Commit the change.
- Pull master down from GitHub again (a precaution - in case it changed).
- Merge your branch with master.
- Checkout the master branch.
- Merge master with your branch.
- Push master up to GitHub.
- Tell your partner, "You're it! Now it's your turn to add a line."
Each person should have a knock knock joke to tell. Start with one player's knock knock joke. Then switch.
-
One person should fork this repository.
- Log on to GitHub, find this repository and click the
Fork
button to create a copy to your own account. - Add the other person as a collaborartor . Go to the Settings section of the repo, find the Collaborator section, and search for them by GitHub username or email.
- Log on to GitHub, find this repository and click the
-
Clone the repository.
- In GitHub on the repository you will share, click the
Clone or download
button and copy the SSH address for the repository (should start with [email protected]). - Log into Cloud 9.
- In terminal in Cloud 9 (make sure you are in the root/outermost folder), type
git
and paste in what you copied from GitHub. Hit Enter. Stuff will happen.
git clone [email protected]:username/some_repository_name.git
- In GitHub on the repository you will share, click the
-
Change your directory into the repository you just cloned.
cd git-knock-knock
-
Create and checkout a branch. (Instead of
my-branch
, give your branch a name you will remember.)git checkout -b my-branch
-
Make a change and save it.
-
Add the changed files to staging. (ie - say, 'yes, those are changes I mean to save')
git add .
-
Commit the change and add a commit message.
git commit -m "Made my first change"
-
Repeat steps 5-7 until your file looks good and your code is tested.
-
Pull down changes from GitHub in case someone on your team has made changes since you started working.
git pull origin master
-
Merge your branch with the master branch. (Instead of
my-branch
, use the name of your branch.)git merge my-branch master
-
Checkout the master branch.
git checkout master
-
Merge master with your branch to close your branch.
git merge master my-branch
-
Push your changes back to GitHub so that others can see them.
git push origin master
git push origin my-branch
If you are not working with branches and are only working on the master branch, here is how you can push your changes to GitHub.
-
Add the changed files to staging. (ie - say, 'yes, those are changes I mean to save')
git add .
-
Commit the change and add a commit message.
git commit -m "Made cool changes"
-
Push your changes back to GitHub so that others can see them.
git push origin master