git for programmers - 17. slon - sedemnajsti slon. for programmers ... • • questions? title:...

Download Git for Programmers - 17. slon - Sedemnajsti slon.  for Programmers ... •  •  Questions? Title: Git for Programmers

Post on 10-Feb-2018




14 download

Embed Size (px)


  • Git for Programmers

    Primo Gabrijeli

  • Kudos

  • Pro Git

    Scott Chacon and Ben Straub

    Pro Git

    Creative Commons Attribution Non Commercial Share Alike 3.0

  • A little bit of history

  • Version Control Systems

    File backups __history

    Local VCS database of changes


    Centralised VCS developer checks out project

    CVS, Subversion, Perforce, Visual SourceSafe

    Distributed VCS Developer mirrors the repository

    BitKeeper, Git, Mercurial, Darcs

  • Git

  • Git

    Mini filesystem

    Stream of snapshots Only changed files are stored

    Almost all operations are local Repository is mirrored locally

    Checksums SHA-1

    File name = data hash

  • File states



    Staged Can be skipped


  • Local configuration

    git config --list

    git config --global core.editor 'C:\Program Files (x86)\PSPadeditor\PSPad.exe'

    git config --edit --global

    git help config


  • Whitespace and newlines

    git config --global core.autocrlf true commit: CRLF -> LF

    checkout: LF -> CRLF

    for Windows-only projects git config --global core.autocrlf false

    CRLF stays CRLF

    core.whitespace LF-delimited

  • Repositories

  • Getting a repository

    Initializing new repository cd project_folder

    git init

    git add files

    git commit m initial commit

    Clone existing repository git clone

    http://, https://, ssh://, git://

  • Files

    git status

    git add

    git diff [--staged]

    git commit [-a] [-m message]

    git rm [--cached]

    git mv git rm + git add

    git commit


  • .gitignore

  • Changelog

    git log [-p] [--stat] [--graph]

  • Ooops!

    git commit --amend AKA Ooops, I forgot that file!

    git reset HEAD AKA unstage

    git config --global alias.unstage reset HEAD

  • RemotesNo programmer is an island

  • Remotes

    git clone

    git remote [-v] origin = name for the default remote repository

    perfectly valid: more than one remote git remote add

  • Pull & Push

    git fetch [] Retrieves the data you dont yet have

    New data goes to the repository, not to your working area

    git pull fetch + merge

    git push []

  • Branching

  • Branches

    A branch is a pointer into commit tree

    git init creates master branch

    git branch

    git log --oneline --decorate

    git checkout

    git checkout --b

    git branch [--merged]

    git branch --d

    branch = lightweight A single file containing 40-char SHA-1 checksum of the commit


  • Merging

    You always work on a branch that is checked out

    git merge

    Resolving merge conflicts > branch1

    git mergetool

    git commit

  • Types of branches

    Long-Running branches master/develop



    Topic branches Short-lived

    A fix for an issue = a branch

  • Remote branches


    git fetch

    git push

    git config push.default current

    git checkout --b

    git push --origin

    git push

  • Tracking branch

    git checkout --b /

    git checkout --track /

    git checkout

    git branch u /

    git pull

  • Rebase

    Take changes committed on one branch and reply them on another one.

    git checkout experimental

    git rebase master

    Do not rebase commits that exist outside your repository.

  • 3-branch rebase

    git rebase [--onto ]

    git rebase --onto master server client


  • Workflows

  • GitFlow


  • GitHub Flow


  • Tools

  • Tools

    Git for Windows


    GitHub Desktop


  • Resources

  • Resources

  • Workflows

  • Questions?