Hacktorial 5 - Intro to Git

“Who even cares about Version Control Systems?”

Everybody’s doing it

Play well in groups

Be a better hacker

Because you take yourself seriously

You’re not smart enough to not use it

“Well what’s so great about version control?”

Git is a camera for your project

and a panic button for when you screw up

It lets you branch out

and merge back painlessly (lol SVN)

Git gives you difference diagnostics

A tag is like a new save file

<3 GitHub

“But the interface is scary and the docs don’t make sense”

I know :(

Aliases and text editor plugins help

“Fine, show me how to use it”


First we need to tell Git to keep track of a project

% pwd

% git init

Tell Git about a new file

% touch index.coffee

% git add index.coffee

% git commit -m "Initial commit."

… and stick it all on ‘the cloud’

% echo $USER

% git remote add origin git@github.com/$USER/hacktorial5

% git push -u origin master

Now your buddy can help you hack

% echo $USER

% git clone https://github.com/zfogg/hacktorial5

Add him to the project on GitHub and start working together :)

“That’s it? Why can’t I just share the folder with him via Dropbox?”

A few problems arise when you collaborate with someone

What if there are merge conflicts?

Two people are working on a project. Both are on the master branch, both are at the same commit.

One person changes a line in a file, the other person deletes the same line in the same file.

One person stages, commits, and pushes their changes. Of course this works just fine; a very standard task for Git.

Now, the second person tries to commit and push their changes.

What will Git do?

What should Git do?

Git has tools to fix code collaboration issues

but sometimes manual work is still required :(

… and that’s why we always work on seperate branches

Working on separate branches reduces bugs when working with others

You should never work on the master branch

Branches on branches

gitflow does all of that stuff for you

Feature, release, hotfix, support.

Got all that?

Thanks for coming!

I’m on Twitter (@zfogg) and Facebook