github-is-awesomeness



github-is-awesomeness

1 0


github-is-awesomeness

Github is Awesomeness - RevealJS Presentation

On Github bholladay / github-is-awesomeness

GitHub is Awesomeness

Git is awesome and GitHub follows suit

Why Git?

  • Ever need a version of a file from 4 days ago?
  • Ever need to see what (or who) changed a file 2 weeks ago?
  • Want to keep every version of an image, layout, or code?
  • Ever need to fix a bug in an old version, but you're working on new version?
  • Ever have two strategies for a solution, and want try them both?
  • Ever work in a group on the same files?
  • Ever need to know what (or who) broke the unit tests and when it happened?

Git can

  • Revert files back to a previous state
  • Compare changes over time
  • See who last modified something.
  • Using a VCS also generally means that if you screw things up or lose files, you can easily recover.
  • You get all this for very little overhead.

GitPro Book

Not just for groups

  • You can save the state of any project as often as you like.
  • You can search over comment messages:
git log --grep=<search>
  • You can search over the actual changes. Use the pickaxe:
git log -S <whatever> --source --all
  • Easy to set up on any project, so why not?
git init

Git is Awesomeness

Git is flexible enough to handle just about any workflow, whether individual or group.

Branches are cheap and merges are easy

(most of the time).

Why GitHub

GitHub is the easiest way to host your public and private repositories

It makes it extremely easy to work in groups, to comment on code, make suggestions, allow others to make suggestions, without code owners losing control of a codebase.

We use it extensively at work to peer review code.

The Most Important Social Network

There is a social network whose sole purpose is facilitating the collaborative production of knowledge and invention: GitHub

Source

Examples:

Discussion of a contribution Discussion of a single line of code Discussion of a bug

Git: The Basics

A quick intro to the major concepts of git.

Git saves the state of your code

You can think about that state as a node on a graph.

Image Source

Some commits have names

Image Source

Master is the main branch name.

All comits have a SHA1 hash name

(like 4dc931002a4cfee3c9e26a7f2767bb9ea8a01265)

Tip: if you lose track of a commit name:

git reflog

Git is distributed

There is a fully functioning repository on each workstation.

Commands:

git clone git@github.com:bholladay/github-is-awesomeness.git

The work moves on

Check for changes

git fetch

New changes, sync them up

git merge origin/master
# OR for a fetch/merge in one
git pull

Git Tips

A shotgun approach

The gitconfig

Use one

[user]
    email="bhsacto@gmail.com"
    name="Bryce Holladay"
[alias]
    # svn aliases
    co=checkout
    ci=commit
    st=status
    br=branch

gitconfig tree visualization

[alias]
# ...
    l = log --graph --pretty=format:'%C(yellow)%h%C(cyan)%d%Creset %s %C(white)- %aN %ar, %ai%Creset'

Hint: You can see the git node tree with branches.

gitconfig external command

git config --global alias.visual '!gitk'

Note: This command just makes an entry in `~/.gitconfig

Without --global the config would get added to the repo .git/config.

Shell integration

Autocompletion

Tough branch names are easy.

Recommend zsh with Oh My Zsh for pre-installed magic.

References: bash, zsh, and others

Command-line status

Reports what branch you are on, whether the repo is dirty, etc.

Github Tips

A smattering of Gitub awesome

Workflow Alternatives

Basic server / client (think svn). Pull Requests Forking with Pull Requests Gitflow - release numbers and hotfixes

Pull Request Workflow

This works well for internal groups.

Branch, branch, branch (even for a small change or fix) Commit often Push once tested (or earlier if you need help/collaboration) git push -u origin <branch_name> Create pull request Tag for code review if ready and @mention reviewers Tag "in progress" if not yet ready Peer Review Merge Delete the branch

Resources:

Discussion of pull requests

GitHub provides references

GitHub automatically creates links in comments when using a git commit SHA-1. Reference issues and PR's with the hashtag #<number> in comments. Cross-references external repos with <user>/<repo>#<issue_number>. Click on the line number to make a custom link to a specific line number. Appends to the URL #L<line_number>.

GitHub Gists

Great for little code snippets, ideas, and pseudocode.

https://gist.github.com/

Whitespace options

Git

git can ignore whitespace in a diff:

git diff -w

Github

Add ?w=1 to any diff URL and GitHub will strip the whitespace.

Original vs whitespace ignored with ?w=1

Pull request best practices.

Make your branches as small as possible. No one wants to review 1200 lines of code.

Dependent branches

If you got a big feature, make bite-sized branches that are dependant on each other. You can go as nested as you need to.

More Tips and Tricks

More topics