Git ft. GitLab

Radionica

Disclaimers

Status

Instalacija

  • cmder ili TortoiseGit @ windows
  • (yum | apt-get) install git @ linux
  • add-apt-repository ppa:git-core/ppa

  • http://git-scm.com/download/mac @ OS X

Konfiguracija

http://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration

$ git config --global user.name "Marin Crnković"
$ git config --global user.email marin@burza.hr

$ git config --global diff.external ~/diff.py
$ git config --global merge.tool meld

$ git config --global alias.up pull
    git up :)
$ ssh-keygen -t rsa

Kreiranje repozitorija kroz Gitlab

  • koristi se grupa "Burza" za komercijalne projekte
  • postoji grupa "infra" za naše interne potrebe (vagrant, puppet, gitlab, ...)
  • postoje grupe developers i frontend za njihove potrebe (frontend/styleguides, developers/bugs)

Kreiranje repozitorija kroz Cli

$ git init
$ git init --bare

Kloniranje repozitorija

$ git clone /path/to/repo.git .
$ git clone git@git.burza.hr:burza/repo.git .

Status

$ git status [--short]
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)

	.gitignore

Diff

$ git diff [FILE]
    prikazuje diff working copy-a sa onime što je u staging-u

$ git diff master [FILE]
    prikazuje diff working copy-a sa masterom
    (ili bilo kojim commitom)

$ git diff --staged
    prikazuje diff staged-a sa zadnjim commitom

$ git diff BRANCH DRUGI_BRANCH
    prikazuje diff između 2 brancha

$ git diff BRANCH...master
    promjene na masteru koje su se dogodile od
    kad je napravljen BRANCH

Revert

$ git checkout FILE
    vraća sadržaj file-a iz zadnjeg komita

$ git reset --hard
    scary shit
    vraća cijeli direktorij na zadnji commit
    (zadržava netrackane fileove)

$ git rm --cached FILE
    briše file iz repozitorija i prestaje ga trackati,
    ali ostavlja u working diru
    

Staging

$ git add FILE
    FILE sa sadržajem U TOM TRENUTKU je stagean za commit
  • Working dir > Staging area > Commit
  • Omogućava nam da pripremimo commit
$ git reset HEAD FILE
    FILE je “unstaged”, neće ići u slijedeći commit
$ git commit -a -m “commitam sve trackane fileove sa -a opcijom, \
i time zaobilazim staging area”

Commit

$ git commit -m “Clearfix all the things!!1one”
$ git commit --amend -m “Add clearfix to .Main-Nav
>
> Added clearfix to help with clearing my fix. 
> Also, it fixes my clears so .Main-Nav is cleared to be fixed”
  • commit sa --amend zamijeni commit, koristi se za pisanje smislenijeg commit message-a ili za dodavanje filea ako smo zaboravili

  • NE KORISTITI na commitovima koje smo već pushali

Pull & Fetch

$ git fetch
$ git merge
OR
$ git pull
$ git remote -v
    izlist svih remote-ova
$ git remote add NAME URL
$ git remote rm NAME

Push

$ git push origin master
$ git push --all
    push-a sve brancheve
$ git push --tags
    push-a sve tagove
$ git push --set-upstream REMOTE BRANCH
    dodaje tracking referencu za svaki branch, 
    omogućuje git pull bez argumenata 
    (git tada “zna” od kuda da pull-a)

Branching

$ git branch [-v]
    popis brancheva
$ git branch mc/feature/clearfix
    kreiranje brancha
    naming convention: initials/type/description
        mc/feature/facebook-v2
        nd/fix/handpicked-widget
        ik/refactor/header-navigation
$ git checkout mc/feature/clearfix
    checkoutanje novokreiranog branch-a
$ git checkout -b mc/feature/clearfix

Merging

$ git checkout master
$ git merge mc/feature/clearfix
    merge brancha "mc/feature/clearfix" u master
    --no-ff argument se može koristiti tako da git ne radi 
    fast forward (update branch pointera), već kreira pravi commit, 
    čime dobivamo na preglednosti kada okinemo git log

$ git branch -d mc/feature/clearfix
    Brisanje brancha

GitLab

Workflow

Homework

Git ft. GitLab

By Marin Crnković

Git ft. GitLab

  • 1,292