SlideShare a Scribd company logo
git入门与实践
ghosTM55
Version Control System
VCS is a kind of system designed to record the changes of
files under control in certain directory
A.K.A Revision Control System
Mainly used in development projects
Local Version Control System
Centralized Version Control System
SVN
CVS
Distributed Version Control System
git
bazaar
BitKeeper
Git
History of git
In 2005, Linux kernel team can't use BitKeeper free of
charge any more
So Linus and other guys designed a brand new distributed
version control system, called git
Inspired by some good features in BitKeeper, git does dvcs
better, especially in speed, it's f***ing fast
Basic concepts about git
git record the stage status and files via snapshot, not like other VCS record
the diff to the former commit .
Nearly all the operations in git can be done locally, so it's more friendly to
the people who can't use network when they want to work on their projects
And of cuz, it's fast due to there is no latency for local operations
git use 40-bit SHA1-HASH to record everything in its repo
Files in git repo may have 4 kind of status
Untracked
Staged
Committed
Modified
git repo is generally made up by three parts
Working directory(git-repo/)
git directory(git-repo/.git/)
Staging area(a file in git directory)
Install git
debian, ubuntu ...
aptitude install git-core
fedora, centos ...
yum install curl-devel expat-devel gettext-devel openssl-
devel zlib-devel
tar xvf git-xxx.tar.gz && cd git-xxx && make all && make
install
yum install git-core(use epel repo maintained by fedora
project)
gentoo
emerge git-core
Mac OS X
get macports && port install git-core
git configuration
Three configuration files using in git
/etc/gitconfig: system-wide configuration
~/.gitconfig: user configuration
git-repo/.git/config:project configuration
git config --global user.name "ghosTM55"
git config --global user.emal "thomas@shlug.org"
git config --global core.editor emacs
'git help config' for more info
Begin git
Initialize a git repo
mkdir git-repo-name && cd git-repo-name && git init
mkdir git-repo.git && cd git-repo.git && git init --bare
Get a git repo from internet (or from other directories local)
git clone git-repo-url
git clone git-repo-url dir-name
github.com
Start to work
Add files to be tracked by git: git add filename
unstage a file: git reset HEAD filename
Checkout the current git status: git status
Commit your work: git commit filename [-a] [-m]
Modify your work and see what happened
diff utility in git: git diff
rename a file tracked by git: git mv filename_a filename_b
remove a file tracked by git: git rm filename
View commit histories
View commit histories: git log
View the last N commit logs: git log -N
View logs one line per commit log: git log --pretty=oneline
View the branch ASCII graph in log: git log --graph
Customize the output format: git log --pretty=format:"format_arguments"
%H Commit hash
%h Abbreviated commit hash
%T Tree hash
%t Abbreviated tree hash
%P Parent hashes
%p Abbreviated parent hashes
%an Author name
%ae Author e-mail
%ad Author date (format respects the date= option)
%ar Author date, relative
%cn Committer name
%ce Committer email
%cd Committer date
%cr Committer date, relative
%s Subject
branch, branch, branch
Killer feature in git
Branch is actually a pointer point to a certain commit .
git use HEAD pointer to determine which branch you're working in
Create a git branch: git branch branch_name
Switch to a certain branch: git checkout branch_name
Delete a branch: git branch -d branch_name
View details about the current branch: git branch -v
Checkout a remote branch: git branch repo_name/branch_name
Merge the works: git merge branch_name
Take care of the conflicts if they exists when you merge
git rebase
git merge vs. git rebase
http://gitguru.com/2009/02/03/rebase-v-merge-in-git/
Milestones
There are two kinds of tags in git
Annotated tag
Lightweight tag
Create an annotated tag: git tag -a tag_ver -m 'comment'
You can sign GPG key in an annotated tag
Annotated tag is a commit
Create a lightweight tag: git tag tag_ver
View details about a tag: git show tag_ver
Push your tags to the repo server: git push repo_name --
tags
Be a victor
Modify the last commit: git commit --amend
Nu-clear option: filter-branch
git filter-branch --tree-filter 'modify script(in bash)' HEAD
git filter-branch --commit-filter '
if [ "$GIT_AUTHOR_EMAIL" = "schacon@localhost" ];
then
GIT_AUTHOR_NAME="Scott Chacon";
GIT_AUTHOR_EMAIL="schacon@example.com";
git commit-tree "$@";
else
git commit-tree "$@";
fi' HEAD
Time machine in git:
git reset --soft commit-SHA1-value
git reset --hard commit-SHA1-value
git on the air
Default remote is called origin
Default branch is called master
Fetch the work on a certain remote repo:
git fetch remote_name [branch_name]
git pull remote_name [branch_name]
Push your work:
git push remote_name branch_name
People mostly use ssh as the git protocol
git clone ssh://user@host:/path/to/git-repo
Misc
Ignore certain files in git working directory: .gitignore
git command alias: git config --global alias.alias_name
'command_name'
Stashing
Create a stash: git stash
Apply a stash: git stash apply
Create a stash branch: git stash branch branch_name
Apply the patches directly in git: git apply patch_file
Another killer feature: git cherry-pick
git cherry-pick --help
merge specified commit to a branch with cherry-pick and
rebase
Migration from SVN: git svn clone svn-repo-url
git workflows
Centralized workflow
Integration-Manager workflow
1. The project maintainer pushes to their public repository.
2. A contributor clones that repository and makes changes.
3. The contributor pushes to their own public copy.
4. The contributor sends the maintainer an e-mail asking them to pull
changes.
5. The maintainer adds the contributor’s repo as a remote and merges
locally.
6. The maintainer pushes merged changes to the main repository.
Dictator and Lieutenants workflow
1. Regular developers work on their topic branch and rebase their work
on top of master. The master branch is that of the dictator.
2. Lieutenants merge the developers’ topic branches into their master
branch.
3. The dictator merges the lieutenants’ master branches into the
dictator’s master branch.
4. The dictator pushes their master to the reference repository so the
other developers can rebase on it.
More resources about git
Pro Git: progit.org
git community book: book.git-scm.com
github.com
http://www.ghostunix.org/blog
Start using it!
Thank you

More Related Content

PPT
Git introduction
satyendrajaladi
 
PDF
Version Control & Git
Jason Byrne
 
PPTX
From svn to git
Nehal Shah
 
PDF
Version control system
Andrew Liu
 
PDF
Git Version Control System
KMS Technology
 
PDF
Version Control System - Git
Carlo Bernaschina
 
PDF
Version Control with Git
Luigi De Russis
 
PDF
Git cheat sheet
Lam Hoang
 
Git introduction
satyendrajaladi
 
Version Control & Git
Jason Byrne
 
From svn to git
Nehal Shah
 
Version control system
Andrew Liu
 
Git Version Control System
KMS Technology
 
Version Control System - Git
Carlo Bernaschina
 
Version Control with Git
Luigi De Russis
 
Git cheat sheet
Lam Hoang
 

What's hot (19)

PDF
Version Control Systems with git (and github) as an example
Gaurav Kumar Garg
 
PDF
Git in 5 Minutes
Robert Dumas
 
PPTX
Techoalien git
Aditya Tiwari
 
PPTX
Advanced Git Presentation By Swawibe
Md Swawibe Ul Alam
 
PDF
Git for beginners
Arulmurugan Rajaraman
 
PPTX
Git 101
jayrparro
 
PPTX
Hacktoberfest intro to Git and GitHub
DSC GVP
 
PPTX
Git commands
Viyaan Jhiingade
 
PDF
Github git-cheat-sheet
Abdul Basit
 
PDF
Tài liệu sử dụng GitHub
viet nghiem
 
PPSX
Git the fast version control system
Jeroen Rosenberg
 
PPTX
Git in 10 minutes
Safique Ahmed Faruque
 
PPTX
Git basics
Denys Haryachyy
 
PPTX
Git
Hanokh Aloni
 
PDF
Git Developer Cheatsheet
Abdul Basit
 
KEY
The everyday developer's guide to version control with Git
E Carter
 
ODP
Git presentation
Vikas Yaligar
 
PPTX
Git and github introduction
John(Qiang) Zhang
 
Version Control Systems with git (and github) as an example
Gaurav Kumar Garg
 
Git in 5 Minutes
Robert Dumas
 
Techoalien git
Aditya Tiwari
 
Advanced Git Presentation By Swawibe
Md Swawibe Ul Alam
 
Git for beginners
Arulmurugan Rajaraman
 
Git 101
jayrparro
 
Hacktoberfest intro to Git and GitHub
DSC GVP
 
Git commands
Viyaan Jhiingade
 
Github git-cheat-sheet
Abdul Basit
 
Tài liệu sử dụng GitHub
viet nghiem
 
Git the fast version control system
Jeroen Rosenberg
 
Git in 10 minutes
Safique Ahmed Faruque
 
Git basics
Denys Haryachyy
 
Git Developer Cheatsheet
Abdul Basit
 
The everyday developer's guide to version control with Git
E Carter
 
Git presentation
Vikas Yaligar
 
Git and github introduction
John(Qiang) Zhang
 
Ad

Viewers also liked (7)

PDF
WCI 10gR3 overview
Terry Wang
 
PDF
交點高雄Vol.16 - Eeddie Li - 決不讓別人影響我的教育
交點
 
PDF
Oracle Buys Ksplice
Terry Wang
 
PDF
我的 Ubuntu 之旅
Terry Wang
 
PDF
Oracle Linux Nov 2011 Webcast
Terry Wang
 
PDF
Eliminating Silent Data Corruption with Oracle Linux
Terry Wang
 
PDF
Btrfs by Chris Mason
Terry Wang
 
WCI 10gR3 overview
Terry Wang
 
交點高雄Vol.16 - Eeddie Li - 決不讓別人影響我的教育
交點
 
Oracle Buys Ksplice
Terry Wang
 
我的 Ubuntu 之旅
Terry Wang
 
Oracle Linux Nov 2011 Webcast
Terry Wang
 
Eliminating Silent Data Corruption with Oracle Linux
Terry Wang
 
Btrfs by Chris Mason
Terry Wang
 
Ad

Similar to Git (20)

PPTX
Introduction to Git and Github
Max Claus Nunes
 
PDF
Git Commands Every Developer Should Know?
9 series
 
PDF
Git basics for beginners
PravallikaTammisetty
 
PPT
390a gitintro 12au
Nguyen Van Hung
 
PPTX
sample.pptx
UshaSuray
 
PDF
Advanced Git Tutorial
Sage Sharp
 
PPTX
tech winter break workshop on git &git hub.pptx
ashishraulin
 
KEY
Git Tech Talk
Chris Johnson
 
PDF
Collaborative development with Git | Workshop
Anuchit Chalothorn
 
PPT
git2.ppt
ssusered2ec2
 
PPTX
Git and Github workshop GDSC MLRITM
gdsc13
 
PPT
git2nvlkndvslnvdslnlknvdlnlvdsnlknsdvlkn.ppt
loleto7559
 
PDF
Subversion to Git Migration
Manish Chakravarty
 
PPTX
Git and GitHub Workshop of GDG on Campus UNSTPB
AmaraCostachiu
 
ODP
Git Workshop : Getting Started
Wildan Maulana
 
DOCX
Git github
Anurag Deb
 
PPT
Git and GitHUB Explanation and simple coding for CLI
kumaresan7751
 
PPT
git2.ppt
MohammadSamiuddin10
 
PPTX
Intro to Git DevOps Tally Presentation 101615
Brian K. Vagnini
 
PDF
Git workflows automat-it
Automat-IT
 
Introduction to Git and Github
Max Claus Nunes
 
Git Commands Every Developer Should Know?
9 series
 
Git basics for beginners
PravallikaTammisetty
 
390a gitintro 12au
Nguyen Van Hung
 
sample.pptx
UshaSuray
 
Advanced Git Tutorial
Sage Sharp
 
tech winter break workshop on git &git hub.pptx
ashishraulin
 
Git Tech Talk
Chris Johnson
 
Collaborative development with Git | Workshop
Anuchit Chalothorn
 
git2.ppt
ssusered2ec2
 
Git and Github workshop GDSC MLRITM
gdsc13
 
git2nvlkndvslnvdslnlknvdlnlvdsnlknsdvlkn.ppt
loleto7559
 
Subversion to Git Migration
Manish Chakravarty
 
Git and GitHub Workshop of GDG on Campus UNSTPB
AmaraCostachiu
 
Git Workshop : Getting Started
Wildan Maulana
 
Git github
Anurag Deb
 
Git and GitHUB Explanation and simple coding for CLI
kumaresan7751
 
Intro to Git DevOps Tally Presentation 101615
Brian K. Vagnini
 
Git workflows automat-it
Automat-IT
 

More from Terry Wang (8)

PDF
Introduction to containers, k8s, Microservices & Cloud Native
Terry Wang
 
PPTX
Debugging and Configuration Best Practices for Oracle Linux
Terry Wang
 
PDF
RHEL roadmap
Terry Wang
 
PDF
Get the Facts: Oracle's Unbreakable Enterprise Kernel
Terry Wang
 
PDF
Git 101 tutorial presentation
Terry Wang
 
PDF
Git 入门 与 实践
Terry Wang
 
PDF
Git 入门与实践
Terry Wang
 
PPT
ALUI 6.5
Terry Wang
 
Introduction to containers, k8s, Microservices & Cloud Native
Terry Wang
 
Debugging and Configuration Best Practices for Oracle Linux
Terry Wang
 
RHEL roadmap
Terry Wang
 
Get the Facts: Oracle's Unbreakable Enterprise Kernel
Terry Wang
 
Git 101 tutorial presentation
Terry Wang
 
Git 入门 与 实践
Terry Wang
 
Git 入门与实践
Terry Wang
 
ALUI 6.5
Terry Wang
 

Recently uploaded (20)

PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PPTX
The Future of AI & Machine Learning.pptx
pritsen4700
 
PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
PPTX
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PDF
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PPTX
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
The Future of AI & Machine Learning.pptx
pritsen4700
 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 

Git

  • 2. Version Control System VCS is a kind of system designed to record the changes of files under control in certain directory A.K.A Revision Control System Mainly used in development projects Local Version Control System Centralized Version Control System SVN CVS Distributed Version Control System git bazaar BitKeeper
  • 4. History of git In 2005, Linux kernel team can't use BitKeeper free of charge any more So Linus and other guys designed a brand new distributed version control system, called git Inspired by some good features in BitKeeper, git does dvcs better, especially in speed, it's f***ing fast
  • 5. Basic concepts about git git record the stage status and files via snapshot, not like other VCS record the diff to the former commit . Nearly all the operations in git can be done locally, so it's more friendly to the people who can't use network when they want to work on their projects And of cuz, it's fast due to there is no latency for local operations git use 40-bit SHA1-HASH to record everything in its repo Files in git repo may have 4 kind of status Untracked Staged Committed Modified git repo is generally made up by three parts Working directory(git-repo/) git directory(git-repo/.git/) Staging area(a file in git directory)
  • 6. Install git debian, ubuntu ... aptitude install git-core fedora, centos ... yum install curl-devel expat-devel gettext-devel openssl- devel zlib-devel tar xvf git-xxx.tar.gz && cd git-xxx && make all && make install yum install git-core(use epel repo maintained by fedora project) gentoo emerge git-core Mac OS X get macports && port install git-core
  • 7. git configuration Three configuration files using in git /etc/gitconfig: system-wide configuration ~/.gitconfig: user configuration git-repo/.git/config:project configuration git config --global user.name "ghosTM55" git config --global user.emal "[email protected]" git config --global core.editor emacs 'git help config' for more info
  • 8. Begin git Initialize a git repo mkdir git-repo-name && cd git-repo-name && git init mkdir git-repo.git && cd git-repo.git && git init --bare Get a git repo from internet (or from other directories local) git clone git-repo-url git clone git-repo-url dir-name github.com
  • 9. Start to work Add files to be tracked by git: git add filename unstage a file: git reset HEAD filename Checkout the current git status: git status Commit your work: git commit filename [-a] [-m] Modify your work and see what happened diff utility in git: git diff rename a file tracked by git: git mv filename_a filename_b remove a file tracked by git: git rm filename
  • 10. View commit histories View commit histories: git log View the last N commit logs: git log -N View logs one line per commit log: git log --pretty=oneline View the branch ASCII graph in log: git log --graph Customize the output format: git log --pretty=format:"format_arguments" %H Commit hash %h Abbreviated commit hash %T Tree hash %t Abbreviated tree hash %P Parent hashes %p Abbreviated parent hashes %an Author name %ae Author e-mail %ad Author date (format respects the date= option) %ar Author date, relative %cn Committer name %ce Committer email %cd Committer date %cr Committer date, relative %s Subject
  • 11. branch, branch, branch Killer feature in git Branch is actually a pointer point to a certain commit . git use HEAD pointer to determine which branch you're working in Create a git branch: git branch branch_name Switch to a certain branch: git checkout branch_name Delete a branch: git branch -d branch_name View details about the current branch: git branch -v Checkout a remote branch: git branch repo_name/branch_name Merge the works: git merge branch_name Take care of the conflicts if they exists when you merge git rebase git merge vs. git rebase http://gitguru.com/2009/02/03/rebase-v-merge-in-git/
  • 12. Milestones There are two kinds of tags in git Annotated tag Lightweight tag Create an annotated tag: git tag -a tag_ver -m 'comment' You can sign GPG key in an annotated tag Annotated tag is a commit Create a lightweight tag: git tag tag_ver View details about a tag: git show tag_ver Push your tags to the repo server: git push repo_name -- tags
  • 13. Be a victor Modify the last commit: git commit --amend Nu-clear option: filter-branch git filter-branch --tree-filter 'modify script(in bash)' HEAD git filter-branch --commit-filter ' if [ "$GIT_AUTHOR_EMAIL" = "schacon@localhost" ]; then GIT_AUTHOR_NAME="Scott Chacon"; GIT_AUTHOR_EMAIL="[email protected]"; git commit-tree "$@"; else git commit-tree "$@"; fi' HEAD Time machine in git: git reset --soft commit-SHA1-value git reset --hard commit-SHA1-value
  • 14. git on the air Default remote is called origin Default branch is called master Fetch the work on a certain remote repo: git fetch remote_name [branch_name] git pull remote_name [branch_name] Push your work: git push remote_name branch_name People mostly use ssh as the git protocol git clone ssh://user@host:/path/to/git-repo
  • 15. Misc Ignore certain files in git working directory: .gitignore git command alias: git config --global alias.alias_name 'command_name' Stashing Create a stash: git stash Apply a stash: git stash apply Create a stash branch: git stash branch branch_name Apply the patches directly in git: git apply patch_file Another killer feature: git cherry-pick git cherry-pick --help merge specified commit to a branch with cherry-pick and rebase Migration from SVN: git svn clone svn-repo-url
  • 16. git workflows Centralized workflow Integration-Manager workflow 1. The project maintainer pushes to their public repository. 2. A contributor clones that repository and makes changes. 3. The contributor pushes to their own public copy. 4. The contributor sends the maintainer an e-mail asking them to pull changes. 5. The maintainer adds the contributor’s repo as a remote and merges locally. 6. The maintainer pushes merged changes to the main repository. Dictator and Lieutenants workflow 1. Regular developers work on their topic branch and rebase their work on top of master. The master branch is that of the dictator. 2. Lieutenants merge the developers’ topic branches into their master branch. 3. The dictator merges the lieutenants’ master branches into the dictator’s master branch. 4. The dictator pushes their master to the reference repository so the other developers can rebase on it.
  • 17. More resources about git Pro Git: progit.org git community book: book.git-scm.com github.com http://www.ghostunix.org/blog