Github-for-everyone



Github-for-everyone

0 0


Github-for-everyone

http://aln787.github.io/Github-for-everyone

On Github aln787 / Github-for-everyone

Github for Everyone

(Unlocking the power of version control / distributed collaboration)

@AlexNiderbergSoftware Engineer - Capital One Labs

Presentation Objectives

  • Provide an approachable overview of version control and Github
  • Leave people excited to find out more, about Git / Github after this session
  • Begin to dig into some of the advanced git features

Capital One

Capital One Labs

Creative / Software Development Life Cycle

I did it!!!

Joy turns to anger so quickly

How can I prevent this from happening again??

How living a version controlled lifestyle can be amazing

  • A few Examples
    • Lots of time and frustration spared, while modifying copy with a team
    • No one has an excuse for not knowing the correct version, they should begin working from
    • A definitive location for finalized assets
    • Product managers and designers are empowered to make simple configuration changes

What is Git?

  • distributed version control system
  • allows you to work off-line
  • provides a collaboration framework

Linus 2007 git overview

Source: Linus 2007 Git Introduction

Using CVCS penalizes you from committing and branching since it is so expensive. This causes developers to have very large commits.
Animation Demo
/Users/xvo202/Development/animationDemo/loginexamples

This repo should have the demo, pull and confirm https://bitbucket.org/aln787/flightinfo

Thats more like it

Key Git Concepts

  • Staging Area / Working Copy
  • Commit Object
  • .git repository
  • Branches
  • Stashing
  • MergingAre git and github the same?

Github Add's PSD support

Edit / Stage / Commit

What you are actually staging is a snapshot. With every change you need to re-add it or stage it using git add.

Making Progress

Freedom and safety

Branches

Branching

- A branch is collection of commit objects When initializing a git repo the default branch is master

    (1) -- (2) -- (3)
                   |
                 master
                   |
                  HEAD
HEAD points to commit (3) on master branch

Visualize the state of different versions of the project

Have standards high standards?

Git empowers you with a frame-work for review explicit changes

Git-flow

I want to try new things!!

Switching to a new branch

    # creates a new branch
    $ git branch [new-branch-name] 
    # move HEAD to point to new branch
    $ git checkout [new-branch-name] 
    $ git checkout -b [new-branch-name]

Stashing

Way so may commits??

Tidying up

Rebasing

  • Clean-up your commit history locally
    • git rebase -i HEAD~3
  • Prepare for a pull request
    • git rebase -i master

Additional clean-up

  • Update the commit message
    • git commit --amend
  • Break changes in to smaller pieces
    • git add -i
  • Update the commit author
    • git commit --amend --author="Your Name <yourEmail@email.com>"

Much better!!

Tagging

git tag v0.3.8
git tag v0.3.8 44a2a4a2bf8b85214551ce93227d4af7981e8eca
git tag --list
git push --tags

What does commit object hold?

  • reference to parent commit, if any
  • tree - set of files conveying current state of the project
  • author info, commiter info, commit message, etc. Commit object is uniquely identified by a 40-character SHA1 hash

Git Repository

Git stores information about your project in .git subdirectory referred to repository

What does .git include?

  • commit objects
  • HEAD - a set of reference to commit objects
  • ..more..

Other Github Features

GH-Pages

  • Reveal-MD/GH-Pages OverviewReview the vertical section titled 'MAKING CREATING PRESENTATIONS FEEL MORE LIKE PROGRAMING' beginning with the slide 'TURNS THIS'.

Reveal.js Resources

Optional Hands-on Exercise

  • Full Instructions
  • Overview
    • From public github, fork my repository
    • Update the place holder values
    • Commit the changes
    • View your example presentation

Suprising how easy that was!

Aside on Markdown

Markdown Resources

Wiki

Wiki examples

Issues

Git in Action

- Status - Init - Clone - Diff - Commit

Check for git repo

$git status
fatal: Not a git repository (or any of the 
parent directories): .git

Initializing Repository

$ mkdir [project-name]
$ cd [project-name]
$ git init
git-collab/
  .git/
    config
    description
    HEAD
    hooks/
    info/
    objects/
    refs/

Cloning existing repository

$ git clone [git-url]
$ git clone https://github.com/vmaliwal/git-collab.git

Untracked Changes / Files

$ git status
On branch master
Your branch is up-to-date with 'origin/master'.

Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

modified:   README.md
modified:   index.html

Untracked files:
(use "git add <file>..." to include in what will be committed)

images/CentralizedVCS.png
images/DistributedVCD.png
images/LinusViewDVCS.png

no changes added to commit (use "git add" and/or "git commit -a")
</file></file></file>

Git Diff

$ git diff README.md 
diff --git a/README.md b/README.md
index f08ca69..10ea20b 100644
- a/README.md
+ b/README.md
@@ -1 +1,9 @@
-### Introduction to Git 
\ No newline at end of file
+### Introduction to Git 
+
+- run
+```
+npm install
+grunt serve
+```
+
+- Make changes by modifying index.html
\ No newline at end of file

Creating a commit object

Create a new file or modify existing

$ echo "Introduction to Git" > README
$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add [file]..." 
# to include in what will be committed)
#
# README
When creating a new file or updating existing file and saving those changes will create a commit object

Add

    
$ git add [file-name]
$ git commit -m "Initial commit"
    
    
$ git add . //to add all modified files, or
$ git commit -a -m "Initial commit"
    

Commit

    
Git commit -a #is the same as using git add and then git commit
git config --global color.ui true
    

Collaboration

  • Distributed version control model to collaborate between multiple developers.

    • Remote repository
    • Pull remote changes
    • Push local changes to remote

Remote repository

  • Remote repositories are versions of your project that are hosted on the Internet or network somewhere.

    • Create a new remote repository(on github, bitbucket, etc.) and clone to your local machine. Or,
    • Add existing git repo from your local machine to remote

Create a new remote repo and clone to your local machine

  • Create new remote repository on github or bitbucket
    $ git clone [git-remote-repo-url].git
  • As name suggests clone command can be used to clone any remote repository

Add existing git repo from local machine to remote

Create new repository on github or bitbucket On your local machine..

$ git remote add origin [git-remote-repo-url].git
$ git push -u origin master

origin is a remote repository reference that git uses

Pulling remote changes

$ git pull [remote-repo-reference] [remote-branch-name]
$ git pull origin master

Pushing changes to remote

$ git push [remote-repo-reference] [remote-branch-name]
$ git push origin master

Multiple Remotes

origin  https://github.com/aln787/git-collab.git (fetch)
origin  https://github.com/aln787/git-collab.git (push)
14109fd767af:git-collab xvo202$ git remote add kdc https://github.kdc.capitalone.com/xvo202/git-collab.git
14109fd767af:git-collab xvo202$ git remote -v
kdc https://github.kdc.capitalone.com/xvo202/git-collab.git (fetch)
kdc https://github.kdc.capitalone.com/xvo202/git-collab.git (push)
origin  https://github.com/aln787/git-collab.git (fetch)
origin  https://github.com/aln787/git-collab.git (push)

Fork and Pull

Fork Exercise

https://github.com/aln787/git-collab/wiki#exercise

Merge conflicts

While pulling or merging a branch merge conflicts can occur due to conflicting changes

Alternatives / Outstanding Issues

Outstanding Issues

  • 100MB file limit
  • Git / Git-hub specialty is text or non-binary files
  • Git has a bit of a learning curve that scares some people off

Alternatives

Pixelapse

- (Y-Combinator project acquired by Drop Box)

Pixelapse - Fast-co article

Proofhub

Other useful links I came across while creating this presentation

Thank you!!!

Appendix

Additional Git Concepts

  • git config
  • vim .gitignore
  • git diff [ --staged | --cached ]
  • git add --patch
  • git [command] --help or man git

Git Config

  • git config --list
  • git config --global user.name "Your Name"
  • git config --global user.email yourEmail@gmail.com
  • git config --global push.default simple #remove verbose messaging about the git 2.0 change
  • git config --global core.editor "subl -n -w" #editor for commit messages
  • git commit -a #will bring up sublimetext so you can enter you commit message

.gitignore the unsung hero

- It is very important to have this file in your project root directory to avoid merge conflicts from auto-generated code from VM, IDE, etc. - Google for gitignore nodejs/golang/java/android/iOS

Diff Options

#git diff [ --staged | --cached ]
$ git status
# At least 1 file is staged
$ git diff --staged
# Reveals the staged changes
$ git reset #to push those changes back to the working copy

Break Changes into Smaller Pieces

#git add --patch [file]
$ git add --patch
#Use s for smaller y, n, ...

Get Git Help

#git [command] --help or man git
$ git diff --help
$ man git
# Then use / to search for --ca

Tips and Tricks

If you are ever unsure what to do when using Git, copy your project directory.

Setting Up SSH Keys

$ ls -al ~/.ssh
$ ssh-keygen -t rsa -b 4096 -C "youremail@email.com"
$ eval "$(ssh-agent -s)"
$ ssh-add ~/.ssh/id_summit2016
$ cat ~/.ssh/id_summit2016.pub 
Then add the output of the cat to your list of github ssh keys on the github site.

$ ssh -T git@github.com
Full Set-up details

Additional Git Commands

  • git diff HEAD^ --word-diff
    • git config --global help.autocorrect1
  • git config --global color.ui 1
  • git commit --amend -C HEAD
    • Use this to add changes you forgot to add to the last commit that are currently staged

References

Github for Everyone (Unlocking the power of version control / distributed collaboration) @AlexNiderberg Software Engineer - Capital One Labs