February 19, 2014
Created by Lucy Bain, @lucykbain
Nowadays Git is part of most developer's work flows. It's a handy tool, and a great one to learn more about. This evening we're going to learn more about Git on it's own, without a full Ruby on Rails project to clutter things up. Instead, we'll write a story.
Some of you may have played this game before. Someone starts a story and writes just one line, then the next person continues the story by adding another line, the next person contributes another line, and so on. Eventually you're left with a story (of sorts) that everyone has contributed to. We're going to play that game, but we'll use Git!
Make sure you have a GitHub account. If you've done Rails Girls before, you should have one already, but this is the time to find your username and password.
I made a repository and Angie made a second repo for today's stories, you'll need to clone your assigned repo and open it in your editor (I'll be using Sublime).
To clone Lucy's repo use git clone git@github.com:lbain/RGN-july-2014.git
, and to clone Angie's repo git clone git@github.com:angiegove/RGN-july-2014-group2.git
.
I'll go through a demo with another leader so you can see all the steps involved. Here's a quick review:
git pull origin master
story.txt
and add a line)git add story.txt
git commit -m "your commit message here"
git push origin master
We'll go around the group so everyone gets a turn. When it's your turn, follow the steps above to add your line to the story. Feel free to be silly and don't worry about typos, we'll fix them later!
There's been some creative differences between myself and another mentor, we want to take the story in different directions. We'll create new branches each and assign you to work on a particular branch.
You need to checkout the branch you're working on with git checkout BRANCH-NAME
Just as we did before, everyone will contribute to the story line one at a time. The commands remain the same, but instead of pull
ing and push
ing to master
you will use your BRANCH-NAME
instead.
At this point, there have probably been a few mistakes, or some plot twists that didn't quite make sense. We'll tidy those up now. But we don't want to go around changing other people's work without asking them. So we'll make a pull request to let them know.
Your mentor will demo how to make a pull request, then it will be your turn.
The main command you'll use is git checkout -b BRANCH-NAME
.
Once everyone has made pull requests, you need to go back and comment on two pull requests that aren't yours. Then head back to your pull request to see what people said about yours, and decide if your pull request should be merged in or closed and left out.
Sometimes you might make changes and forget to run a git pull
first, or someone else might git push
changes while you're making changes of your own. This can cause merge conflicts. Here's how we'll simulate this:
git pull
, make a change to the story, and then git commit
git push
git push
, but should get rejectedgit pull
, resolve the merge conflict, and git commit
git push
, successfully this timeGo around the group and get everyone to be person 1 and person 2 so everyone has resolved a merge conflict.