nge-git (belajar git bareng)

220
nge-Git bareng Mizan

Upload: mizan-riqzia

Post on 13-Apr-2017

345 views

Category:

Technology


9 download

TRANSCRIPT

nge-Gitbareng Mizan

Perkenalkan

MizanGeneral Manager T’Labhttp://tlab.co.id

Pengguna Git

Ilkomp 2006

Semacam apa Git ?

Git

Open sourcedistributed version control system

designed for speed & efficiency

Apa pula Version Control?

● Sistem untuk mencatat perubahan data

● Memungkinkan pengembangan secara bersama

● Tahu siapa yang merubah dan kapan data dirubah

● Memungkinkan mengembalikan data seperti semula

Version Control

Git

mercurial (hg)

bazaar

subversion (svn)

concurrent version system (cvs)

perforce

visual source safe

Contoh Version Control

Apa maksud distributed version control ?

(Hampir) semua data berada di lokal

Keuntungan Data di Lokal

● Ada backup

● Bekerja jadi lebih cepat

● Bekerja offline (tanpa koneksi internet)

Apa yang bisa dilakukan tanpa Internet

● Performing a diff

● Viewing file history

● Committing change

● Merging branches

● Obtaining other revisions of a ifle

● Switching branches

Maksud

“designed for speed & efficiency” ?

Data (hampir) tidak dihapus

Data di-Snapshots

Perbedaan Patch & Snapshots

Storing data as changes to a base version of each file

Storing data as snapshots of the project over time

Basic Git

Langkah awal

$ git config --global user.name “Mizan”

$ git config --global user.email “[email protected]

Getting a Repo

Membuat Repo

Git init

$ touch README.md

$ git init

$ tree -a.├── .git│ ├── branches│ ├── config│ ├── description│ ├── HEAD│ ├── hooks│ │ ├── applypatch-msg.sample│ │ ├── commit-msg.sample│ │ ├── post-update.sample│ │ ├── pre-applypatch.sample│ │ ├── pre-commit.sample│ │ ├── prepare-commit-msg.sample│ │ ├── pre-push.sample│ │ ├── pre-rebase.sample│ │ └── update.sample│ ├── info│ │ └── exclude│ ├── objects│ │ ├── info│ │ └── pack│ └── refs│ ├── heads│ └── tags└── README.md

10 directories, 14 files

$ tree -a.├── .git│ ├── branches│ ├── config│ ├── description│ ├── HEAD│ ├── hooks│ │ ├── applypatch-msg.sample│ │ ├── commit-msg.sample│ │ ├── post-update.sample│ │ ├── pre-applypatch.sample│ │ ├── pre-commit.sample│ │ ├── prepare-commit-msg.sample│ │ ├── pre-push.sample│ │ ├── pre-rebase.sample│ │ └── update.sample│ ├── info│ │ └── exclude│ ├── objects│ │ ├── info│ │ └── pack│ └── refs│ ├── heads│ └── tags└── README.md

10 directories, 14 files

$ touch README.md

$ git init

$ git add .

tree -a.├── .git│ ├── branches│ ├── config│ ├── description│ ├── HEAD│ ├── hooks│ │ ├── applypatch-msg.sample│ │ ├── commit-msg.sample│ │ ├── post-update.sample│ │ ├── pre-applypatch.sample│ │ ├── pre-commit.sample│ │ ├── prepare-commit-msg.sample│ │ ├── pre-push.sample│ │ ├── pre-rebase.sample│ │ └── update.sample│ ├── index│ ├── info│ │ └── exclude│ ├── objects│ │ ├── e6│ │ │ └── 9de29bb2d1d6434b8b29ae775ad8c2e48c5391│ │ ├── info│ │ └── pack│ └── refs│ ├── heads│ └── tags└── README.md

11 directories, 16 files

$ touch README.md

$ git init

$ git add .

$ git commit -m ‘first commit’

tree -a.├── .git│ ├── branches│ ├── COMMIT_EDITMSG│ ├── config│ ├── description│ ├── HEAD│ ├── hooks│ │ ├── applypatch-msg.sample│ │ ├── commit-msg.sample│ │ ├── post-update.sample│ │ ├── pre-applypatch.sample│ │ ├── pre-commit.sample│ │ ├── prepare-commit-msg.sample│ │ ├── pre-push.sample│ │ ├── pre-rebase.sample│ │ └── update.sample│ ├── index│ ├── info / exclude│ ├── logs│ │ ├── HEAD│ │ └── refs / heads / master│ ├── objects│ │ ├── e6 / 9de29bb2d1d6434b8b29ae775ad8c2e48c5391│ │ ├── f9 / 3e3a1a1525fb5b91020da86e44810c87a2d7bc│ │ ├── ff / 0952b14f24609b47d910df46ee944650f60054│ │ ├── info│ │ └── pack│ └── refs│ ├── heads / master│ └── tags└── README.md

16 directories, 22 files

Membuat Repo Clone

Git Clone

$ git clone [email protected]:laravel/laravel.git

Atau

$ git clone https://github.com/laravel/laravel.git

$ git clone https://github.com/laravel/laravel.gitCloning into 'laravel'...remote: Counting objects: 25800, done.remote: Compressing objects: 100% (41/41), done.remote: Total 25800 (delta 23), reused 0 (delta 0), pack-reused 25759Receiving objects: 100% (25800/25800), 9.69 MiB | 116.00 KiB/s, done.Resolving deltas: 100% (12922/12922), done.Checking connectivity... done.$ cd laravel$ lsapp composer.json gulpfile.js phpunit.xml resources testsartisan config package.json public server.phpbootstrap database phpspec.yml readme.md storage

A Basic Workflow

A Basic Workflow

● Edit files

● Stage the changes

● Review your changes

● Commit the changes

A Basic Workflow

● Edit files● Stage the changes

● Review your changes

● Commit the changes

$ vim README.md

# My First Git

Senangnya bisa menggunakan git

$ git statusOn branch masterChanges not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in..

modified: README.md

no changes added to commit (use "git add" and/or "git com..

A Basic Workflow

● Edit files

● Stage the changes● Review your changes

● Commit the changes

Git Add

$ git add .$ git statusOn branch masterChanges to be committed: (use "git reset HEAD <file>..." to unstage)

modified: README.md

$ git add .$ git statusOn branch masterChanges THAT ARE STAGED: (use "git reset HEAD <file>..." to unstage)

modified: README.md

stage filesetelah melakukan perubahan

stage filesetelah melakukan perubahan

A Basic Workflow

● Edit files

● Stage the changes

● Review your changes

● Commit the changes

Git commit

$ git commit

mencoba commit# Please enter the commit message for your changes. Lines ..# with '#' will be ignored, and an empty message aborts ..# On branch master# Changes to be committed:# modified: README.md

$ git commit[master e0b06a1] mencoba commit 1 file changed, 4 insertions(+)

A Basic Workflow

● Edit files vim / emacs / etc

● Stage the changes git add (file)

● Review your changes git status

● Commit the changes git commit

A Basicer Workflow

● Edit files vim / emacs / etc

● Stage & Commit git commit -a

Another Basic Git

Another Basic Git

● Ignoring Files

● Removing Files

● Moving Files

Ignoring Files

.gitignore

$ touch .gitignore$ vim .gitignore.env$ touch .env$ git statusOn branch masterUntracked files: (use "git add <file>..." to include in what will be..

.gitignore

nothing added to commit but untracked files present..

$ git add .$ git commit -m ‘add gitignore’

Removing Files

git rm <file>

$ git rm README.md$ git statusOn branch masterChanges to be committed: (use "git reset HEAD <file>..." to unstage)

deleted: README.md

Moving Files

git mv <file>

$ git mv README.md README$ git statusOn branch masterChanges to be committed: (use "git reset HEAD <file>..." to unstage)

renamed: README.md -> README

Undo

Undo Commit

git commit --amend

Unstaging a Staged File

git reset HEAD <file>

Unmodifiying a Modified File

git checkout -- <file>

Branching

git branch & git checkout

Git Merge

Non linear development

● clone the code that is in production● create a branch for issue #53 (iss53)● work for 10 minutes● someone ask for a hotfix for issue #102● checkout ‘production’● create a branch (iss102)● fix the issue● checkout ‘production’ merge ‘iss102’● push ‘production’● checkout ‘iss53’ and keep working

Distributed Workflow

fetch, pull, & push

pull = fetch + merge

a Who in the what now?

Multiple Remotes

Popular Workflows

Central Repository Model

Dictator and Lieutenants Model

Integration Manager Model

Remotes Are Branches

Working with Remotes

Showing Your Remotes

git remotegit remote -v

Adding Remote Repositories

git remote add <remote-name> <URL>

Fetching & Pulling from Remotes

git remote <remote-name>

Pushing to Your Remotes

git push <remote> <branch>

Inspecting a Remote

git remote show <remote-name>

Renaming & Remove Remotes

git remote rename <remote-name> <remote-newname>

git remote rm <remote-name>

Tagging

Listing Your Tags

git tag

Creating Tags

Lightweight tag Annotated tags(pointer) (store as full object)

Annotated Tags

git tag -a <tagname>

Listing Lightweight Tags

git tag <tagname>

Tagging Later

git tag -a <tagname> <commit>

Sharing Tags

git push <remote> <tagname>

Checking out Tags

git checkout -b <branchname> <tagname>

Thank you for watching

any question?