git & GitHub

whoami

 

@julia_allyce

JavaScript Developer @ Bitovi

Consulting and OSS

 

thas my dog Gertrude 💁

What is git?

"Git (/ɡɪt/) is a widely used version control system for software development. It is a distributed revision control system with an emphasis on speed, data integrity, and support for distributed, non-linear workflows. Git was initially designed and developed by Linus Torvalds for Linux kernel development in 2005."

uhhh...thanks a lot wikipedia

In Other Words...

  • git keeps track of changes to files
     
  • Enables many people to work on the same files without conflicting with each other
     
  • git keeps track of software versions
     
  • Enables people to work on many versions of the same application, while only keeping one copy of your app.
     
  • git is AWESOMEEEEEE

Repository

Your entire project that git is "watching".

my-app

Do this:

$ mkdir my-first-repo
$ cd my-first-repo/
$ git init
Initialized empty Git repository
in /Users/julia/my-first-repo/.git/

Commit

A saved record of your repository's state at a specific time

my-app

my-app

my-app

Oct 20, 2015 @ 10:32AM

Oct 20, 2015 @ 03:15PM

Oct 21, 2015 @ 02:44AM

"Initial Commit"

"Added New Images"

"New ReadMe.md"

Do this:

$ touch readme.md
$ git status
$ git add .
$ git commit -m "Initial Commit"
[master (root-commit) 70fe53c] Initial Commit
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 readme.md

Branch

A unique "timeline" or "stream" for commits.

Master

Development

New Feature

Do this:

$ git checkout -b develop
Switched to a new branch 'develop'
$ touch .gitignore
$ git add .
$ git commit -m "Added gitignore file"
[develop 75403b0] Added gitignore file
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 .gitignore

Do this:

$ git log
commit 75403b0f43f42ca984a157877728e9b16a295fac
Author: Julia Poladsky <sdfsdfsdf@sdfsdf.com>
Date:   Tue Oct 20 18:14:27 2015 -0400

    Added gitignore file

commit 70fe53ca158a26cb404ebcafdb763f9938b87eb0
Author: Julia Poladsky <sdfsdfsdf@asdsdf.com>
Date:   Tue Oct 20 18:05:51 2015 -0400

    Initial Commit

$ git checkout master
$ git log
commit 70fe53ca158a26cb404ebcafdb763f9938b87eb0
Author: Julia Poladsky <sdfsdfsdf@asdfsdfs.com>
Date:   Tue Oct 20 18:05:51 2015 -0400

    Initial Commit

Do this:

$ git branch
  develop
* master

Merge

When one commit stream joins("merges into") another.

Master

Development

New Feature

Do this:

$ git merge develop
Updating 70fe53c..75403b0
Fast-forward
 .gitignore | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 .gitignore


$ git log
commit 75403b0f43f42ca984a157877728e9b16a295fac
Author: Julia Poladsky <sdfsdfsdf@sdfsdf.com>
Date:   Tue Oct 20 18:14:27 2015 -0400

    Added gitignore file

commit 70fe53ca158a26cb404ebcafdb763f9938b87eb0
Author: Julia Poladsky <sdfsdfsdf@asdsdf.com>
Date:   Tue Oct 20 18:05:51 2015 -0400

    Initial Commit

Local vs. Remote

Local is the copy of the repository on your machine. Remote is a hosted copy of the repository, typically lives on something like GitHub

Do this:

Click the create button down here... oops

Do this:

$ git remote add origin YOUR-REPO-URL
$ git push -u origin master

Counting objects: 5, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (5/5), 448 bytes | 0 bytes/s, done.
Total 5 (delta 0), reused 0 (delta 0)
To git@github.com:julia-allyce/my-first-repo.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.

Push

Pushing updates the "Remote" repository with your latest commits.

Woot. We Did that! 

$ git push
// Pushes your current branch 
// to your default remote

$ git push REMOTE_NAME BRANCH_NAME

https://git-scm.com/docs/git-push

Cavet

`git push` before 2.0 used to push ALL your local repos...not anymore

😌

Pull

Fetches and merges in the latests commits from remote. 

$ git pull
// Pulls commits for current branch  
// from your default remote

$ git push REMOTE_NAME BRANCH_NAME

https://git-scm.com/docs/git-pull

Pull Requests

A polite way to merge code by asking for approval/review.

Example

Merge Conflicts!

Merge conflicts arise when two commits change the same files, and git cannot reconcile the changes.

Identifying Conflicting Files:

Resolving the Conflict:

Staged vs. Unstaged

When files are "staged" they are ready to be logged in a commit. Any unstaged files will be ignored.

Example:

Example:

Example:

Made with Slides.com