03 Version Control and Branch Management (Git)
03 Version Control and Branch Management (Git)
Management (Git)
OUR RULES
“Revision Is A Must,
Don’t Expect Every Code is Perfect”
TOOLS Version Control System (VCS)
Source Code Manager (SCM)
Revision Control System (RCS)
VERSION CONTROL SYSTEM
SCCS - 1972 Unix only
Single User RCS - 1982 Cross platform, text only
Git - 2005
Distributed Mercurial - 2005
Bazaar - 2005
GIT
Salah satu version control system populer yang
digunakan para developer untuk mengembangkan
software secara bersama-bersama
Real World
Collaboration
TERDISTRIBUSI
Bukan tersentralisasi
DIBUAT OLEH
Linus Torvalds (2005) - Linux Kernel
https://github.com/torvalds/linux
EVERYONE SHOULD SYNC TO THE
REMOTE SERVER
REMOTE
COMPUTER / SERVER
$ git --version
git version 2.9.2
INSTALL GIT WINDOWS
1. Download the latest Git for Windows installer.
2. When you've successfully started the installer, you should see
the Git Setup wizard screen. Follow the Next and Finish
prompts to complete the installation. The default options are
pretty sensible for most users.
3. Open a Command Prompt (or Git Bash if during installation you
elected not to use Git from the Windows Command Prompt).
INSTALL GIT LINUX
1. From your shell, install Git using apt-get:
output
$ git --version
git version 2.9.2
SETTING UP
GIT INIT, CLONE, CONFIG
output
# git config
$ git config --global user.name “John Done”
$ git config --global user.email “[email protected]”
working directory
git add
staging area
git commit
repository
GIT STATUS, ADD, COMMIT
output
$ git status
Notice how this doesn’t work for the other non-imperative forms:
● If applied, this commit will fixed bug with Y
● If applied, this commit will changing behavior of X
● If applied, this commit will more fixes for broken stuff
● If applied, this commit will sweet new API methods
GIT DIFF AND STASH
output
# git diff
# change file
# add staging area
$ git diff --staged
33
GIT RESET
--soft --hard
35
SYNCING
GIT PUSH, FETCH & PULL
output
# git remote
$ git remote -v
$ git remote add origin http://dev.example.com/john.git
# push
$ git push origin master
$ git push origin feature/login-user
BRACHES
GIT BRANCHING
output
39
GIT MERGE
output
40
PULL REQUEST
PULL REQUEST
WORKFLOW
COLLABORATION
Objectives Understand the proper
workflow to collaborate
with GitHub or Gitlab
How to optimize
your workflow with
GitHub or Gitlab?
DO YOU WORK LIKE
THIS ?
OR LIKE THIS ?
THE BEST WAY LIKE THIS
LET
THE MASTER
1 BRANCH
UNDISTURBED
$ (master) git branch development
$ (master) git checkout development
AVOID MAKING
DIRECT EDIT
2 ON
DEVELOPMENT
$ (development) git branch feature1
$ (development) git checkout feature1
APPLY THE
FEATURE TO
3 DEVELOPMENT
ONLY
$ (feature1) git checkout development
$ (development) git merge feature1
*) git rebase will prevent you from conflicts when merging feature branch to development branch
APPLY
DEVELOPMENT
TO MASTER
4 WHEN IT’S
DONE
$ (master) git merge development
ANY QUESTION
Frequently
Asked
Question
“The Best Way of
Learning about Anything
is by Doing”
WORKFLOW
COLLABORATION
Bagaimana cara
mengoptimalkan
kolaborasi dalam
development?
dalam kolaborasi tim kita tidak bisa
hanya bekerja dalam satu branch
master
perlu dibuat beberapa branch agar
kolaborasi dapat berjalan dengan optimal
master
develop
feature
feature
BUAT
BRANCH MASTER
1 DARI BRANCH
DEVELOPMENT
develop D
master M
2 KE BRANCH
DEVELOPMENT
F2
feature
feature F1
develop D
master M
3 HANYA KE
BRANCH DEVELOPMENT
F2
feature
feature F1 F1x
develop D Dx
master M
*) git rebase akan mencegah konflik ketika merge dari branch feature ke branch development
MERGE BRANCH
DEVELOPMENT
KE BRANCH MASTER
4 JIKA DEVELOPMENT
SELESAI
develop D Dx
master M Mx