github

I went today to a Git/GitHub training organized by Canoo and lead by Tim Berglund (GitHub.com) The online training presentation is available at http://teach.github.com/presentations/git-foundations.html use first left key then left/right/up and bottom keys to navigate through the slides.

My notes are still under reviews, but are available at http://gittraining.waltercedric.com

GitHub also offers free, short, topical online classes about GitHub, Git and the union of these two technologies Here.

GIT training

  • Tim Berglund
  • config
    • global
      • user level config for logged in user
    • local
      • use when pushing to github later
    • system
      • apply to every user logged in on the machine
    • Git autodetect file type
      • binary
      • text
        • CRLF

          • dont mess with it if it is working

          Colorize console output for legibility
          git config --global color.ui auto

          Force files to be LF in the repo, even on Mac/Linux
          git config --global core.autocrlf input

          Force Windows to convert to CRLF
          # on checkout and to LF on `add`
          git config --global core.autocrlf true

    • Git Help
      • git help config
        • To print and read
  • 1. Staging area
    • first add
      • git init newproject
      • cd newproject
      • vi caesar.txt
      • git status
        • file red
          • untracked
          • modified
      • git add caesar.txt
        • file green = tracked
        • it is now in staging
      • refs are name for objects
        • ex master
      • modifiy the file
        • vi caesar.txt
      • file has to go to staging before being committed
        • git add caesar.txt
          • go in staging
          • when in staging the file has no refs
        • git commit -m "small change"
          • now has a name associated to it
    • Why
      • so you can work on paralell files or topics
        • is it not a bad sign?
      • you can also commit then later "part" of the file
        • you could break easily since unit test may be broken with half file
      • advance command
        • revert
          • not like subversion
        • cherry pick
        • only if you know what it is in your stagign area
  • 4. Branching
    • HEAD
      • equals to most recent commit
      • is going to be the parent of the next commit
      • it is where the branch live
      • master is just another branch
      • a branch is at least 2 commit with the same parent
    • branch is fast because it is local
    • Play
      • create a branch
        • git branch feature
        • this do not switch to the branch
      • move to branch
        • git checkout feature

          check where you are working

          • git branch
          • git status

          vi caesar.txt

          git add caesar.txt

          git commit -m "add a title"

          git lg

      • merge feature to master
        • git checkout master
        • git merge feature
        • and kill that branch
          • better not used it if its a feature
    • git reset
      • if we discover an error in commit message 259a4c9
      • hard
        • reset both master and any branch
          • like merge has never happen
          • blow up old commit and create new ons!
          • dangerous you can lose code
      • Play
        • git reset --hard 259a4c9
        • git commit --amend
          • commits are lost
            • you can not find it
            • still there as an object but has no refs!
            • you have to remember the hash
            • may be garbage collected after 60 days
            • git reflog
              • may be still in there
        • you can then redo a git merge feature
      • better use rebase
        • 95% of git users dont know how
        • quite advanced
    • git branch adopted 259a4c9
      • create a branch adopted of the amended commit
    • delete the branch
      • git branch -d feature
        • delete the label of the branch
        • but the commit stay of course
      • git branch -d adopted
        • will complains as not merged
        • force the delete of non merged
        • git branch -D adopted
  • 5. merge conflict
    • GIT search for chunk that are similar and can merged automatically
    • Play
      • git merge feature
      • git status
        • show merge conflict
    • if you know what is in reflog
      • git reset --hard HEAD@{1}
      • you can undo last command
      • not always 1 command lead to only one entry in reflog
      • use with precaution
    • external merge tool
      • p4merge
        • config
          • git config --global merge.tool p4merge
          • git config --global mergetool.prompt false
          • git config --global mergetool.keepBackup false
          • git config --global mergetool.keepTemporaries false
        • use
          • git mergetool
    • to solve merge conflict on binary file
      • automatic merge not possible
      • you can decide your or theirs is the right one
      • git checkout --theirs -- animated.gif
        • git add animated.gif
          • git commit -m "use their version of binary animated.gif"
  • 7. GitHub
    • git remote add origin https://xxxxx/yyyy.git
      • create a local config at .git/config
      • origin is a convention name
    • git push
      • push unique content to remote
      • git push -u origin master
        • -u to make master

          remember that it

          track remote origin

      • git branch -a
        • now display also remote branch in red
    • git help daemon
      • share

        to start a git server

        to server your local

        git repo as a remote

        for colleagues

    • git help bundle
      • no network?

        write objects and refs into files

        for sharing on cdrom or

        shared drive

        for highla secure environment

        without network: ex military

    • git fetch
      • get all objects, blobs and commit

        but do not change master

        • just get and save commits

          in local remote area (read only)

          git checkout feature5

          • feature5 being in remote origin
          • will create a local branch feature5
    • git pull
      • do a git fetch and merge into master
    • git push
      • need no parameter but use push.default if it exist
      • every local branch will be pushed as default if none have been specified
      • use
        • git config --global push.default simple
          • to only push the branch where you have
          • set it if you dont know te default
        • git help config
          • upstream
          • simple
          • ...
      • when pushing failed
        • failed to push some refs upstream

          because there is a new commit

          in master which is ahead of mine

          fast forwards will work

          only if i have new stuff

          • git pull (make a merge)

            git push

            better would have been to

            make a rebase also to clear

            the noise of merging to push

    • Fun
  • 9. Collaborating
    • Play
      • git config --global credential.helper cache

        • work only in linux/mac

        vi cedric.txt

        git add .

        git commit -m "add file"

        git push

        • if not succed do a git pull

        gitk --all

        • see a lot of noise because

          of merge done by pull before

          each push

        force to rebase on pull is a

        good idea to remove noise

        • git config --local branch.master.rebase true
        • or better
          • git config --global branch.autosetuprebase always

    • tags
      • 3 differents

        • reference
          • git tag XXXXX hash
            • it is a reference
            • always point to commit
        • annotated
          • -a --annotate Make an unsigned, annotated tag object
          • git tag -a ANNOTATED_TAG
          • is an indirection to a tag
        • ...

        tags are not pushed

        by default to origin

        • git push
          • do nothing
        • git push origin ANNOTATED_TAG
          • push a specific tag
        • git push --tags
          • push all tags

        delete

        • a tag
          • git tag -d tagname
        • a branch
          • git push --delete origin branchname
          • git push origin :branchname
  • revealJS
  • filesystem
    • Hooks
      • entry point to hook
    • refs
    • objects
    • HEAD
      • commit youre on
  • 2. Log history
    • # git log
    • hash
      • 40 character hash
    • git log --format= email
    • git log --format=raw
      • useful for training
      • relationship tree -> parent -> author -> committer
        • it is a graph
          • important to understand
        • git log --graph
        • git log --graph --decorate --format=oneline
          • still a lot of hash
        • git log --graph --decorate --format=oneline --abbrev-commit
    • git log --patch
      • Show all history with patches
    • aliases
      • git lol
        • git config --global alias.lol "log --graph --decorate --oneline --all"

          http://boyen.github.com

          • like a puppet for developer
      • git lg
        • git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --all"

  • 3. Diff
    • git diff
    • git diff --staged
      • what is my next commit will do?
    • git diff --word-diff
    • git diff HEAD
      • show changes between local and something in history
    • create scripts
      • ~/scripts/git-xxxxxx
      • ~/scripts/git-log
    • git log ec7674 -1 --patch
      • to look at a particular commit and its diff
    • git show ec7674
  • 4. move and rename
    • remove a file from VCS and keep local copy
      • git rm --cached -- <filename>
      • git commit -m "remove from vcs"
    • GIT integrity check
      • each commit contains at least one tree and one or more blobs
      • content is king
      • blobs
        • store file content
        • no permissions
        • no metadata
        • each blob is stored under first 2 character of hash directory in /objects
        • every change of a file create a NEW blob
          • diff is calculating the diff on demand

            not storing them like svn

      • tree
        • contains file name
        • references to one or many blobs
        • one to n tree in a commit
      • git pack
        • all commits can get packed to find similar blob
        • 5 to 10 times less space than SVN
      • git GC
        • find all commits, trees and blobs

          that can not be accessed and remove them

    • git add -u .
      • update only tracked file not moved/renamed  file
      • use instead
        • git add -A .
    • git checkout -- file3.txt
      • revert file content
    • similarity content analyser
      • if more then 50% then it count the the file as renamed otherwise it is new
      • git log -2 --stat
        • may show delete + add for a move operations
      • git log -2 --stat -M
        • display also similarity index
        • may show move correctly
        • git log -2 --stat -M90
          • with 90% similarity threashold
        • git log -2 --stat -M -- file3.txt
          • limit to file
        • git log -2 --stat -M --follow -- file3.txt
          • changes + move + create
  • 6. Rebase
    • interactive rebase
    • rewrite the history
      • changing authors or any other properties
    • preparation for merging
      • Rebase Rebase Fastforward
        • ex: to make my code changes in branch

          appear like a continuation of master

          • d19' = d19
          • e69' = e69
          • but still different commits!

          do it in branch

          you want to move

          • git rebase master
            • change shape of the graph

              keep timestamp and author

              pull of all commits of a branch &

              replay all commit in master

              • may create small conflicts

          make the history straightforward

          • especially if you have a lot of branches
            • otherwise look like a train station
          • but you hide informations
            • from which branch it was merged
      • non fastforward
      • history
        • is a graph not a list like in "git log"
        • it is not temporal but topological
    • interactive rebase
      • to group commits into one
        • "commits are stories not just checkpoints"
      • git rebase -i [start, end]
        • start = HEAD as default
        • end = hash
        • git rebase -i HEAD^
          • parent of head
          • you can combine HEAD^^^^^^
        • git rebase -i HEAD~10
          • last 10 commit
        • git rev-parse HEAD^
          • give hash
        • git help gitrevisions
          • adavnce list of expressions
        • create a file so you can decide what to do
          • has command
          • pick, reword, edit,squash, fixup and exec
          • you can not squash the oldest commit
  • 8. Forking
    • Play
      • git clone xxxx
      • vi xxxxx.txt
      • git add .
      • git commit -m ""
      • git push
      • open a pull request
    • pull request
      • invitation to start a conversation
      • add metadata
        • screenshots
        • emoji-cheat-sheet.com
      • is an iterative process
        • threaded discussion
    • ideas
      • when opening  a feature branch
        • create a pull request immediately
        • improve communication and awareness and start discussion
        • even if there is no code yet done
    • merge conflict can not be solved in github
      • has to be done in command line
comments powered by Disqus

You might like also

No Thumbnail was found
work in progress - daily update Feedback is welcome in comments section, or through my contact form click on map, to view in full size …
31 Days ago
How to: Securing your Crypto  Assets
work in progress - daily update - a more convenient online version is also hosted at https://github.com/cedricwalter/Securing-Crypto-Assets  Pull requests are welcomed! Feedback is welcome in comments section, or through my contact form click on map, to view in full size …
31 Days ago
Big Bang Blockchain: La seconde révolution d'internet de Stéphane Loignon
La blockchain est annoncée comme une révolution technologique, économique, politique et sociétale aussi puissante qu’Internet. Cette « chaîne de blocs » promet d’être l’outil incontournable de demain. À quoi sert la blockchain ? Cette nouvelle technologie permet avant tout d’envoyer de l’argent en ligne sans intermédiaire : ni banque, ni compagnie de carte de crédit. Elle pourrait bouleverser la finance, l’assurance et le transfert d’argent tout en étant le moteur d’un vaste mouvement de décentralisation de l’économie numérique. Grâce à elle, certains rêvent …
49 Days ago
Blockchain definitions
  Blocks & Transactions Transaction data is permanently recorded in files called blocks. They can be thought of as the individual pages of a city recorder's recordbook (where changes to title to real estate are recorded) or a stock transaction ledger. Blocks are organized into a linear sequence over time ("Miner" or "Worker") also known as the block chain). New transactions are constantly being processed by Miners (into new blocks which are added to the end of the chain and …
50 Days ago
No Thumbnail was found
DevFest is the biggest Google tech conference in Switzerland. All about machine learning, programming, emerging technologies and much more!  GDG DevFests are large, community-run developer events happening around the globe focused on community building and learning about Google’s technologies. This year i will be helping and organizing some of the side activities between the talk session. And i prepared a lot of stuff, enough for 11 screens! _auto_generated_thumb_ _auto_generated_thumb_ Not everything is on pictures, NES and SNES classic are missing …
55 Days ago
Mining FeatherCoin on GeForce 1080 Ti
Feathercoin is a powerful open source digital currency with monetary properties linked to Bitcoin, Litecoin and a myriad of countless alt coins, but under the hood is something very different. Feathercoin is a highly upgraded and customised piece of software compared to the Bitcoin and Litecoin protocols. Based from Bitcoin, Litecoin evolved, from which Feathercoin was born, with the intent to expand, experiment, and build onto the blockchain technology in a manner open to all for participation. Just over one …
56 Days ago
No Thumbnail was found
XMR-Stak is a universal Stratum pool miner. This is the NVIDIA GPU mining version; there is also an AMD GPU version, and a CPU version. Docker® containers are often used to seamlessly deploy CPU-based applications on multiple machines. But Docker Engine does not natively support NVIDIA GPUs with containers. I have dockerized the Nvidia GPU-mining version, so it is now running in nvidia-docker. Containerizing GPU applications provides several benefits, among them: Reproducible builds Ease of deployment Isolation of individual devices Run across heterogeneous …
77 Days ago
Running WordPress and MySql in Docker
Notes A Docker image is a lightweight, stand-alone, executable package of a piece of software that includes everything needed to run it: code, runtime, system tools, system libraries, settings. Available for both Linux and Windows based apps, containerized software will always run the same, regardless of the environment. Containers isolate software from its surroundings, for example differences between development and staging environments and help reduce conflicts between teams running different software on the same infrastructure. A container is a runtime …
149 Days ago
No Thumbnail was found
182 Days ago
Dropbox CLI on linux
Dropbox is a free service that lets you bring all your photos, docs, and videos anywhere. This means that any file you save to your Dropbox will automatically save to all your computers, phones and even the Dropbox website. Dropbox creates a special folder on the user's computer, the contents of which are then synchronized to Dropbox's servers and to other computers and devices that the user has installed Dropbox on, keeping the same files up-to-date on all devices. I …
194 Days ago