2. Introduction
´Distributed Version Control System (DVCS)
´Free opensource (inspired from BitKeeper)
´Original author: Author Linus Torvald
´Initial release 7 April 2005; 13 years ago
´Current mainter Junio Hamano (gitter) Google engineer
4. Overview - Concept
1. Git thinks about its data more like a stream of snapshots.
Commit, or save the state it basically takes a picture of what all your files look like at that
moment and stores a reference to that snapshot
5. Overview - concept
1. Integrity - Nearly Every Operation Is Local
Everything in Git is check-summed before it is stored and is then referred to by that
checksum.
2. Git Generally Only Adds Data
When you do actions in Git, nearly all of them only add data to the Git database
8. Git basic
1. Install
2. Clone new project
3. Git config
# ubuntu
sudo apt-get install git
# centos
yum install git
# Macos
brew install git
# public repo not require ssh key
git clone git@github.com:jwasham/coding-interview-university.git
# public repo not require user/password
git clone https://github.com/jwasham/coding-interview-university.git
# config for local (--local). For global (--global)
git config --local user.name 'kan kan’
git config --local user.email ’buikhanh.bk@gmail.com’
9. Git basic
3. Init local repo
4. Push to git server
git init
git add LICENSE.md README.md
# add all file (not recommend when working)
git add .
# commit to git at local
git commit –m ‘init project’
# list remote link to server
git remote –v
# add 1 link to git repo. Usually using origin
git remote add origin git@github.com:1Rhino/coding-interview-university.git
# add another git remote link
git remote add hopee git@github.com:1Rhino/coding-interview-university.git
# push to server git
git push origin master (git push hopee master)
10. Git basic
5. create branch
6. Pull data
# create new branch develop
git branch develop
# jump to branch develop
git checkout develop
# create new branch and jump to it (ussually)
git checkout –b develop
# fetch data from server to local but not merge
git fetch origin develop
# merge data from branch develop to master (current branch: master)
git merge develop
# fetch data from server and merge to current branch
git pull origin develop
14. Git basic
8. History
9. Ignore
# list history commit
git log
git log --pretty="%h - %s”
# blame last edit
git blame
# create file .gitignore to ignore all unnessarry file
node_modules/
log/
*.log
__CACHE
__data/
15. Git basic
10. Alias
# using git alias
git config --global alias.co checkout à git co
git config --global alias.br branch à git br
git config --global alias.ci commit à git ci
git config --global alias.st status. à git st
# using system. add alias to ~/.zshrc ~/.bash_profile…
alias ga='git add’. à ga
alias gc='git commit -m’ à gc
alias gp='git pull origin’
alias gpu='git push origin’
alias gc='git commit -m'