git



git

3 0


git

https://aln787.github.io/git/

On Github aln787 / git

Unleashing Github

(Unlocking the power of version control / distributed collaboration)

@AlexNiderbergiOS and Android Reliability Engineering - Capital One

Presentation Objectives

  • Provide an overview of version control with Git and Github
  • Begin exploring into some of the advanced git features
  • Leave you excited become a version control master

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??

Living a version controlled lifestyle

  • 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.

Here we go!

Centralized VCS

Source: Illustrated Distributed Version Control

Distributed VCS

Source: Illustrated Distributed Version Control

Every copy of a git branch becomes it's own branch when it falls off line or out of sync with origin. Git has a built in check for disk / file corruption since files are tracked using a hash. ##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..

Commit Object

git cat-file -p master
git cat-file -p a7ba36a62d8d8a40d4d9bc4386cc1ae174aff555
cat-file -p cfcae178cfcf1948c2aca252ebed8146c8aada4f

Getting started

Here we go now

Key Git Concepts

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

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.

Off to a good start

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
    #Switching branches
    $ git checkout [branch-name]

Branches let me try new things!!

Animation Demo
/Users/xvo202/Development/animationDemo/loginexamples

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

Stashing

Visualize the state of different versions of the project

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

That is great if you have standards!

Usage Patterns: e.g. Git-flow

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
git push origin v0.3.8

Github Tools / 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

Collaboration

  • Distributed version control model to collaborate between multiple developers.

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

Collaboration Example

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

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

3 Things

  • Power / responsibility associated with Git / Github
  • Advanced features
  • Portable skill, so be come an expert

Thank you!!!

References

Appendix

Alternatives / Outstanding Issues for designers

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

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
  
Unleashing Github (Unlocking the power of version control / distributed collaboration) @AlexNiderberg iOS and Android Reliability Engineering - Capital One