Làm việc với Git

January 01 2011 · 2 minute read · git

Git là phần mềm quản lý mã nguồn phân tán được phát triển bởi Linus Torvalds dành cho việc phát triển Linux kernel.

Qui trình Git cơ bản

Dữ liệu trong repository được Git quản lý theo ba tree: Working Directory, Index (stage)HEAD (commit) 1 theo qui trình sau:

Các lệnh dùng trong qui trình

Đây là một Git workflow đơn giản với các nguyên tắc cơ bản 2:

# everything is happy and up-to-date in master
git checkout master
git pull origin master

# let's branch to make changes
git checkout -b my-new-feature

# go ahead, make changes now.
$EDITOR file

# commit your (incremental, atomic) changes
git add -p
git commit -m "my changes"

# keep abreast of other changes, to your feature branch or master.
# rebasing keeps our code working, merging easy, and history clean.
git fetch origin
git rebase origin/my-new-feature
git rebase origin/master

# optional: push your branch for discussion (pull-request)
#           you might do this many times as you develop.
git push origin my-new-feature

# optional: feel free to rebase within your feature branch at will.
#           ok to rebase after pushing if your team can handle it!
git rebase -i origin/master

# merge when done developing.
# --no-ff preserves feature history and easy full-feature reverts
# merge commits should not include changes; rebasing reconciles issues
# github takes care of this in a Pull-Request merge
git checkout master
git pull origin master
git merge --no-ff my-new-feature

# optional: tag important things, such as releases
git tag 1.0.0-RC1