Loading

Git Introduction for Beginners

Aaron Wang

This is a live streamed presentation. You will automatically follow the presenter and see the slide they're currently on.

Git introduction 

for beginners


Aaron Wang

What's git

  • A distributed version control system
  • A content-addressable file system
  • A stupid content tracker
  • Write code
  • Write book: https://www.gitbook.io/
  • Started by Linus Torvalds for Linux kernel development @ 2005

Git characteristics

  • Distributed &  Decentralized, client == server
  • Fast Branching & Merging
  • Efficient In Storage & Network
  • Toolkit Based Design
    • Over a hundred commands, countless options...
  • Flexible Workflow

Local operations

  • Git Directory
  • Working Directory
  • Index(Stage/Cache)

get started

  • git help <command>
  • git config --global user.name <name>
    git config --global user.email <email>
    .git/config > ~/.gitconfig > /etc/gitconfig
  • git init/git clone <url> 
  • git status, git diff
  • git add, git diff --cached
  • git commit -m <message>
  • .gitignore: https://github.com/github/gitignore
  • git log

What's a good commit

Revert changes

  • uncached: git checkout <paths>
  • cached: git reset <tree-ish> -- <paths>
  • committed:
    • git reset <tree-ish> -- <paths>; git checkout <paths>
    • git reset <commit> --hard
    • git revert <commit>

Remote Operations

  • git clone <url>
    • https://github.com/git/git.git
    • ssh
      • scp style: git@github.com:git/git.git
      • ssh://git@github.com/git/git.git
    • /home/git/git.git
    • git://github.com/home/git/git.git
  • git remote
  • git pull == git fetch + git merge
  • git pull --rebase == git fetch + git rebase
  • git push

Understanding branch

  • git checkout -b <name>
  • git branch
  • git checkout -t <remote>/<branch>
  • git merge <name>[, solve conflicts, git commit]
  • Branch is just a ref to a commit
  • It moves
                   X --- Y --- Z
                 /                          \
    A --- B --- C --- D --- H
  • git push <remote> <src>:<dst>
  • git push <remote> :<dst>

Data Model


Directed Acyclic Graph

glossary

GLOSSARY

  • dangling: unreachable
  • detached: arbitrary commit in HEAD, not a particular branch
  • dirty: uncommitted modifications
  • fast-forward: no merge commit is needed
  • hash: object name
  • ref: SHA1 or name, .git/refs/
  • tree-ish: a ref pointed to either a commit object, a tree object, or a tag object
  • ......

Centralized workflow

  • Like the other VCSs
  • "Better not use git as svn!"

Feature Branch

  • Develop features in separated branch
  • pull/merge requests

gitflow


http://nvie.com/posts/a-successful-git-branching-model/

gitflow

  • apt-get install git-flow
  • git flow init
  • git flow feature start/finish <name>
  • git flow release start/finish <name>
  • git flow hotfix start/finish <name>

tuisongbao dev process

  • git fetch
  • git checkout -t origin/develop -b whatsThisBranchFor
  • # Coding...
  • # Fetch new code on origin/develop in the middle
  • git stash
  • git pull --rebase
  • git stash pop
  • # Coding...
  • git add && git commit
  • git pull --rebase
  • git push origin whatsThisBranchFor -f

Quick tips

  • Conquer Git
    • Read The Output & RTFM
    • Read books, systematic learning
    • Practice
  • git stash: anonymous commit
  • committed/stashed changes are recoverable
    • git reflog
    • git cherry-pick
  • apt-get install gitk git-extras
  • Display git status in your command prompt
    • Customize PS1
    • Use oh-my-zsh plugin

References

https://github.com/inetfuture/technote/blob/master/git.md

HOMEWORK

  • merge vs rebase
    • git rebase -i
  • merge algorithom (optional)

What's gitlab

  • An open source copy of GitHub
  • Self hosted git management application
    • Users / Groups / Projects
    • Access Control
    • Merge Request / Code Review
    • Web Hooks
    • GitLab Flavored Markdown
    • Simple Issue Tracker
    • Simple Wiki System

How gitlab works


Tuisongbao code review process

  • Committer rebase feature branch onto to newest develop branch & push it to GitLab
  • Open a merge request to develop branch & assign to code reviewer
  • Reviewer do the code reivew
    • Point out issues: inconsistent coding style/convention, incorrect logic, missed edge case check, code smell, etc
    • Learn good parts from it
    • Knowing what the committer is working on, how is it going
  • Committer fix issues until reviewer is satisfied
  • Reviewer reassign the MR to develop branch maintainer
  • Maintainer merge it in

Markdown



Thanks

Made with Slides.com