SlideShare a Scribd company logo
Basic Git
2014/07/11
Casper Chen (USGI)
Why Git
• Centralized Version Control System: svn
– can’t develop without connection to VCS server
– this is slow
• Distributed Version Control System: git
– develop locally without connection to VCS server
– repository backup isn’t problem: every clone is also a
backup
• Git
– fast
– less-space for repository
– cheap local branch
2
Distributed VCS
3Computer A Computer B
Repository ServerRepository Server
Version 1
Version 2
Local RepositoryLocal Repository
Version 1
Local RepositoryLocal Repository
Version 2
FilesFiles FilesFiles
pull push
checkout commit
…
Install Git
• In Ubuntu Linux
– sudo apt-get install git
• In Fedora Linux
– sudo yum install git
• In Windows
– http://msysgit.github.com/
– http://code.google.com/p/tortoisegit/
• In Mac
– http://code.google.com/p/git-osx-installer/
4
Configure Git
• Configure the full name to be recorded in any new commit:
git config --global user.name ”Full Name”
• Configure email address to be recorded in any new commit:
git config --global user.email ”user@email.com"
• Always use colors in all git commands:
git config --global color.ui true
• Configure the editor to edit messages when commit or tag:
git config --global core.editor vim
• Specify how many context lines of diff should be displayed:
git config --global gui.diffcontext 5
• Global configuration is in ~/.gitconfig
• For more detailed, please reference “git help config”
5
Initialize Local Repository
1. Enter the directory that you want to manage
by git
– Ex. cd project
1. git init
2. git add --all . (or git add --all --force . to alow
adding otherwise ignored files)
3. git commit --message=“Init”
4. Change description of repository: echo
“description” > .git/description
6
Import Empty Folder to Repository
• touch empty_path/.gitignore
• Add .gitignore to every empty folder
– find . ( -type d -empty ) -and ( -not -regex
./.git.* ) -exec touch {}/.gitignore ;
• The content of .gitignore
# Ignore everything in this directory
*
# Except this file
!.gitignore
7
Build Remote Repository
1. git clone --bare my_project my_project.git
2. Change description of repository: echo
“description” > my_project.git/description
3. Copy my_project.git to remote site
− Ex. Copy to /home/gitserver/my_project.git of
remote site: scp -r my_project.git
gituser@192.168.1.1:/home/gitserver
8
Clone Repository from Remote
Repository
• git clone local_project_path
• git clone user@remote.ip:project_path
• git clone ssh://user@remote.ip:project_path
• Ex. git clone
gituser@192.168.1.1:/home/gitserver/my_pr
oject.git
9
Three areas
10
Working
directory
Staging area Repository
git addgit add
git commitgit commit
git checkoutgit checkout
Submit change to Local Repository
• git add some_files_changed
• git commit
11
Update Local or Remote Repository
• Update local repository from remote’s update
– git pull
– git fetch && git merge
• Update remote repository from local’s
changes
– git push
• Using “git cola” to push for specified branch
12
Remove, move, or rename file
• Delete file
– git rm file_name
• Move or rename file
– git mv file_org file_mod
13
Diff
• Compare the working directory with a specified
commit
– git diff commit
– Ex. git diff 1aj93u5
• Compare two of commits
– git diff commit_1 commit_2
– Ex. git diff 1aj93u5 239ann
• Compare the working directory with staged area
– git diff --staged
14
Clean
• Remove all untracked directories and files
– git clean -df
• Remove all files included file list in .gitignore
– git clean -x
15
Reset
• Back to specified commit
– git reset commit
– Ex. git reset 1aj93u5
• Keep modification in working tree
– git reset HEAD^
• Keep modification in staging area
– git reset HEAD^ --soft
• Destroy all modification
– git reset HEAD^ --hard
• Using gitk 16
Tag
• List all tags
– git tag
• Add a new tag
– git tag -a tagname -m “message for tag”
– Ex. git tag -a v0.1 -m “this is v0.1”
• Delete an existing local tag
– git tag -d tagname
• Send all tags to remote repository
– git push --tags
• Delete the tag of remote repository
– git push origin :refs/tags/tag_name
17
Branch• List local existing branches
– git branch
• List both local and remote branches
– git branch -a
• Create a new local branch and switch to it
– git checkout -b branch_name
• Create a new local branch starts from remote branch
– git checkout -b branch_name start_poing
– ex. git checkout -b development original/dev_branch
• Switch to an existing branch
– git checkout branch_name
• Delete an existing local branch
– git branch -d branch_name
• Send an branch to remote repository
– git push origin branch_name
• Delete the existing branch of remote repository
– git push origin :branch_name 18
Change remote HEAD to point to
another branch
• In remote git repository folder
– git symbolic-ref HEAD refs/heads/branch_name
– git update-server-info
19
Rename remote branch
• Rename the branch in the local repository
– git branch -m old_branch new_branch
• Remove the remote branch
– git push origin :old_branch
• Push the new local branch name to remote
– git push origin new_branch
20
Merge remote branch from local
commits
• git remote add remote_branch_name
remote_path
• git fetch remote_branch_name
• git cherry-pick -n commit_1 commit_2 …
• Ex.
– git remote add develop
gituser@192.168.1.1:/home/gitserver/my_project
.git
– git pull develop
– git cherry-pick abc def 21
Build Git Mirror Repository
• This method needs implementation of password-less
SSH login.
• In git mirror site:
– git clone --mirror original.address:original.git mirror.git
– cp mirror.git/hooks/post-
receive.sample mirror.git/hooks/post-receive
– echo “git push -q” >> mirror.git/hooks/post-receive
– chmod a+x mirror.git/hooks/post-receive
• In original git site:
– cp original.git/hooks/post-
receive.sample original.git/hooks/post-receive
– echo “ssh mirror.address 'cd original.git && git fetch -q”
>> original.git/hooks/post-receive
– chmod a+x original.git/hooks/post-receive
22
Add new branch for new codes to
exist remote repository
• In local new codes
– follow steps 1~4 on page 5
– rename default branch name
• git branch -m master new_branch
– add remote url
• git remote add remote_name remote_path
• Ex. git remote add origin
gituser@192.168.1.1:/home/gitserver/my_project.git
– push to remote repository
• git push remote_name new_branch
• Ex. git push origin new_branch 23
Git Web
• Install Git Web package
– sudo apt-get install gitweb
• Configure Git Web
– sudo vim /etc/gitweb.conf
– Root path of Git Web: $projectroot
• Restart Apache HTTP server
– sudo service apache2 restart
– http://localhost/gitweb
24
GUI tools for Ubuntu
• git cola
– sudo apt-get install git-cola
– commit, push, pull, diff, …
• gitk
– sudo apt-get install gitk
– Display all branches and tags: gitk --all
• tig - GUI in command line
– sudo apt-get install tig
– Display all branches and tags: tig --all
25
git cola
26
gitk --all
27
tig
• tig --all
• tig status
• tig
28
Other Resources
• Git Immersion
– http://gitimmersion.com/
• Git Pro (English)
• http://git-scm.com/book
• Git Pro ( 简体中文 )
• http://git-scm.com/book/zh
• Git Magic (English)
– http://www-cs-students.stanford.edu/~blynn/gitmagic/
• Git Magic ( 繁體中文 )
– http://www-cs-students.stanford.edu/~blynn/gitmagic/intl/zh_tw/
• Git 教育訓練課程投影片 (2012) form ihower
– http://ihower.tw/blog/archives/6696/
29
Ad

More Related Content

What's hot (20)

Gitting out of trouble
Gitting out of troubleGitting out of trouble
Gitting out of trouble
Jon Senchyna
 
Now i git it!!!
Now i git it!!!Now i git it!!!
Now i git it!!!
Yoram Michaeli
 
Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git Tutorial
Sage Sharp
 
Git - Basic Crash Course
Git - Basic Crash CourseGit - Basic Crash Course
Git - Basic Crash Course
Nilay Binjola
 
Git for beginners
Git for beginnersGit for beginners
Git for beginners
Arulmurugan Rajaraman
 
Presentacion git
Presentacion gitPresentacion git
Presentacion git
Ignacio Martín
 
Git tutorial
Git tutorial Git tutorial
Git tutorial
TingYen Lee
 
Git
GitGit
Git
Gayan Kalanamith Mannapperuma
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
Elli Kanal
 
Intro to Git DevOps Tally Presentation 101615
Intro to Git DevOps Tally Presentation 101615Intro to Git DevOps Tally Presentation 101615
Intro to Git DevOps Tally Presentation 101615
Brian K. Vagnini
 
Introduction to Gitlab | Gitlab 101 | Training Session
Introduction to Gitlab | Gitlab 101 | Training SessionIntroduction to Gitlab | Gitlab 101 | Training Session
Introduction to Gitlab | Gitlab 101 | Training Session
Anwarul Islam
 
Git Tech Talk
Git  Tech TalkGit  Tech Talk
Git Tech Talk
Chris Johnson
 
Advanced Git Presentation By Swawibe
Advanced Git Presentation By SwawibeAdvanced Git Presentation By Swawibe
Advanced Git Presentation By Swawibe
Md Swawibe Ul Alam
 
Git submodule
Git submoduleGit submodule
Git submodule
Olaf Alders
 
Learn Git Basics
Learn Git BasicsLearn Git Basics
Learn Git Basics
Prakash Dantuluri
 
GIT | Distributed Version Control System
GIT | Distributed Version Control SystemGIT | Distributed Version Control System
GIT | Distributed Version Control System
Mohammad Imam Hossain
 
Git in 10 minutes
Git in 10 minutesGit in 10 minutes
Git in 10 minutes
Safique Ahmed Faruque
 
Git Basics at Rails Underground
Git Basics at Rails UndergroundGit Basics at Rails Underground
Git Basics at Rails Underground
Ariejan de Vroom
 
Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notes
glen_a_smith
 
Git is my hero
Git is my heroGit is my hero
Git is my hero
Selena Deckelmann
 

Similar to Basic git (20)

Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITM
gdsc13
 
Git Tutorial I
Git Tutorial IGit Tutorial I
Git Tutorial I
Jim Yeh
 
Git session Dropsolid.com
Git session Dropsolid.comGit session Dropsolid.com
Git session Dropsolid.com
dropsolid
 
git-and-bitbucket
git-and-bitbucketgit-and-bitbucket
git-and-bitbucket
azwildcat
 
Git
GitGit
Git
Terry Wang
 
Git 入门与实践
Git 入门与实践Git 入门与实践
Git 入门与实践
Terry Wang
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github
Max Claus Nunes
 
Git 入门 与 实践
Git 入门 与 实践Git 入门 与 实践
Git 入门 与 实践
Terry Wang
 
390a gitintro 12au
390a gitintro 12au390a gitintro 12au
390a gitintro 12au
Nguyen Van Hung
 
Git training v10
Git training v10Git training v10
Git training v10
Skander Hamza
 
Git and github fundamental
Git and github fundamentalGit and github fundamental
Git and github fundamental
Rajesh Kumar
 
tech winter break workshop on git &git hub.pptx
tech winter break workshop on git &git hub.pptxtech winter break workshop on git &git hub.pptx
tech winter break workshop on git &git hub.pptx
ashishraulin
 
11 git version control
11 git version control11 git version control
11 git version control
Wasim Alatrash
 
sample.pptx
sample.pptxsample.pptx
sample.pptx
UshaSuray
 
GIT & COMPOSER __BASIC_git git git git.pptx
GIT & COMPOSER __BASIC_git git git git.pptxGIT & COMPOSER __BASIC_git git git git.pptx
GIT & COMPOSER __BASIC_git git git git.pptx
entonk2
 
Getting started with git
Getting started with gitGetting started with git
Getting started with git
Pawan Kumar.v
 
Git Obstacle Course: Stop BASHing your head and break down the basics
Git Obstacle Course: Stop BASHing your head and break down the basicsGit Obstacle Course: Stop BASHing your head and break down the basics
Git Obstacle Course: Stop BASHing your head and break down the basics
Chris Bohatka
 
Git-guidance for beginner- IT support.pptx.pptx
Git-guidance for beginner- IT support.pptx.pptxGit-guidance for beginner- IT support.pptx.pptx
Git-guidance for beginner- IT support.pptx.pptx
vietnguyen1989
 
Git-guidance for beginner- IT support.pptx
Git-guidance for beginner- IT support.pptxGit-guidance for beginner- IT support.pptx
Git-guidance for beginner- IT support.pptx
vietnguyen1989
 
git.ppt.pdf
git.ppt.pdfgit.ppt.pdf
git.ppt.pdf
Roniel Lopez Alvarez
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITM
gdsc13
 
Git Tutorial I
Git Tutorial IGit Tutorial I
Git Tutorial I
Jim Yeh
 
Git session Dropsolid.com
Git session Dropsolid.comGit session Dropsolid.com
Git session Dropsolid.com
dropsolid
 
git-and-bitbucket
git-and-bitbucketgit-and-bitbucket
git-and-bitbucket
azwildcat
 
Git 入门与实践
Git 入门与实践Git 入门与实践
Git 入门与实践
Terry Wang
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github
Max Claus Nunes
 
Git 入门 与 实践
Git 入门 与 实践Git 入门 与 实践
Git 入门 与 实践
Terry Wang
 
Git and github fundamental
Git and github fundamentalGit and github fundamental
Git and github fundamental
Rajesh Kumar
 
tech winter break workshop on git &git hub.pptx
tech winter break workshop on git &git hub.pptxtech winter break workshop on git &git hub.pptx
tech winter break workshop on git &git hub.pptx
ashishraulin
 
11 git version control
11 git version control11 git version control
11 git version control
Wasim Alatrash
 
GIT & COMPOSER __BASIC_git git git git.pptx
GIT & COMPOSER __BASIC_git git git git.pptxGIT & COMPOSER __BASIC_git git git git.pptx
GIT & COMPOSER __BASIC_git git git git.pptx
entonk2
 
Getting started with git
Getting started with gitGetting started with git
Getting started with git
Pawan Kumar.v
 
Git Obstacle Course: Stop BASHing your head and break down the basics
Git Obstacle Course: Stop BASHing your head and break down the basicsGit Obstacle Course: Stop BASHing your head and break down the basics
Git Obstacle Course: Stop BASHing your head and break down the basics
Chris Bohatka
 
Git-guidance for beginner- IT support.pptx.pptx
Git-guidance for beginner- IT support.pptx.pptxGit-guidance for beginner- IT support.pptx.pptx
Git-guidance for beginner- IT support.pptx.pptx
vietnguyen1989
 
Git-guidance for beginner- IT support.pptx
Git-guidance for beginner- IT support.pptxGit-guidance for beginner- IT support.pptx
Git-guidance for beginner- IT support.pptx
vietnguyen1989
 
Ad

Recently uploaded (20)

Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Ad

Basic git

  • 2. Why Git • Centralized Version Control System: svn – can’t develop without connection to VCS server – this is slow • Distributed Version Control System: git – develop locally without connection to VCS server – repository backup isn’t problem: every clone is also a backup • Git – fast – less-space for repository – cheap local branch 2
  • 3. Distributed VCS 3Computer A Computer B Repository ServerRepository Server Version 1 Version 2 Local RepositoryLocal Repository Version 1 Local RepositoryLocal Repository Version 2 FilesFiles FilesFiles pull push checkout commit …
  • 4. Install Git • In Ubuntu Linux – sudo apt-get install git • In Fedora Linux – sudo yum install git • In Windows – http://msysgit.github.com/ – http://code.google.com/p/tortoisegit/ • In Mac – http://code.google.com/p/git-osx-installer/ 4
  • 5. Configure Git • Configure the full name to be recorded in any new commit: git config --global user.name ”Full Name” • Configure email address to be recorded in any new commit: git config --global user.email ”[email protected]" • Always use colors in all git commands: git config --global color.ui true • Configure the editor to edit messages when commit or tag: git config --global core.editor vim • Specify how many context lines of diff should be displayed: git config --global gui.diffcontext 5 • Global configuration is in ~/.gitconfig • For more detailed, please reference “git help config” 5
  • 6. Initialize Local Repository 1. Enter the directory that you want to manage by git – Ex. cd project 1. git init 2. git add --all . (or git add --all --force . to alow adding otherwise ignored files) 3. git commit --message=“Init” 4. Change description of repository: echo “description” > .git/description 6
  • 7. Import Empty Folder to Repository • touch empty_path/.gitignore • Add .gitignore to every empty folder – find . ( -type d -empty ) -and ( -not -regex ./.git.* ) -exec touch {}/.gitignore ; • The content of .gitignore # Ignore everything in this directory * # Except this file !.gitignore 7
  • 8. Build Remote Repository 1. git clone --bare my_project my_project.git 2. Change description of repository: echo “description” > my_project.git/description 3. Copy my_project.git to remote site − Ex. Copy to /home/gitserver/my_project.git of remote site: scp -r my_project.git [email protected]:/home/gitserver 8
  • 9. Clone Repository from Remote Repository • git clone local_project_path • git clone [email protected]:project_path • git clone ssh://[email protected]:project_path • Ex. git clone [email protected]:/home/gitserver/my_pr oject.git 9
  • 10. Three areas 10 Working directory Staging area Repository git addgit add git commitgit commit git checkoutgit checkout
  • 11. Submit change to Local Repository • git add some_files_changed • git commit 11
  • 12. Update Local or Remote Repository • Update local repository from remote’s update – git pull – git fetch && git merge • Update remote repository from local’s changes – git push • Using “git cola” to push for specified branch 12
  • 13. Remove, move, or rename file • Delete file – git rm file_name • Move or rename file – git mv file_org file_mod 13
  • 14. Diff • Compare the working directory with a specified commit – git diff commit – Ex. git diff 1aj93u5 • Compare two of commits – git diff commit_1 commit_2 – Ex. git diff 1aj93u5 239ann • Compare the working directory with staged area – git diff --staged 14
  • 15. Clean • Remove all untracked directories and files – git clean -df • Remove all files included file list in .gitignore – git clean -x 15
  • 16. Reset • Back to specified commit – git reset commit – Ex. git reset 1aj93u5 • Keep modification in working tree – git reset HEAD^ • Keep modification in staging area – git reset HEAD^ --soft • Destroy all modification – git reset HEAD^ --hard • Using gitk 16
  • 17. Tag • List all tags – git tag • Add a new tag – git tag -a tagname -m “message for tag” – Ex. git tag -a v0.1 -m “this is v0.1” • Delete an existing local tag – git tag -d tagname • Send all tags to remote repository – git push --tags • Delete the tag of remote repository – git push origin :refs/tags/tag_name 17
  • 18. Branch• List local existing branches – git branch • List both local and remote branches – git branch -a • Create a new local branch and switch to it – git checkout -b branch_name • Create a new local branch starts from remote branch – git checkout -b branch_name start_poing – ex. git checkout -b development original/dev_branch • Switch to an existing branch – git checkout branch_name • Delete an existing local branch – git branch -d branch_name • Send an branch to remote repository – git push origin branch_name • Delete the existing branch of remote repository – git push origin :branch_name 18
  • 19. Change remote HEAD to point to another branch • In remote git repository folder – git symbolic-ref HEAD refs/heads/branch_name – git update-server-info 19
  • 20. Rename remote branch • Rename the branch in the local repository – git branch -m old_branch new_branch • Remove the remote branch – git push origin :old_branch • Push the new local branch name to remote – git push origin new_branch 20
  • 21. Merge remote branch from local commits • git remote add remote_branch_name remote_path • git fetch remote_branch_name • git cherry-pick -n commit_1 commit_2 … • Ex. – git remote add develop [email protected]:/home/gitserver/my_project .git – git pull develop – git cherry-pick abc def 21
  • 22. Build Git Mirror Repository • This method needs implementation of password-less SSH login. • In git mirror site: – git clone --mirror original.address:original.git mirror.git – cp mirror.git/hooks/post- receive.sample mirror.git/hooks/post-receive – echo “git push -q” >> mirror.git/hooks/post-receive – chmod a+x mirror.git/hooks/post-receive • In original git site: – cp original.git/hooks/post- receive.sample original.git/hooks/post-receive – echo “ssh mirror.address 'cd original.git && git fetch -q” >> original.git/hooks/post-receive – chmod a+x original.git/hooks/post-receive 22
  • 23. Add new branch for new codes to exist remote repository • In local new codes – follow steps 1~4 on page 5 – rename default branch name • git branch -m master new_branch – add remote url • git remote add remote_name remote_path • Ex. git remote add origin [email protected]:/home/gitserver/my_project.git – push to remote repository • git push remote_name new_branch • Ex. git push origin new_branch 23
  • 24. Git Web • Install Git Web package – sudo apt-get install gitweb • Configure Git Web – sudo vim /etc/gitweb.conf – Root path of Git Web: $projectroot • Restart Apache HTTP server – sudo service apache2 restart – http://localhost/gitweb 24
  • 25. GUI tools for Ubuntu • git cola – sudo apt-get install git-cola – commit, push, pull, diff, … • gitk – sudo apt-get install gitk – Display all branches and tags: gitk --all • tig - GUI in command line – sudo apt-get install tig – Display all branches and tags: tig --all 25
  • 28. tig • tig --all • tig status • tig 28
  • 29. Other Resources • Git Immersion – http://gitimmersion.com/ • Git Pro (English) • http://git-scm.com/book • Git Pro ( 简体中文 ) • http://git-scm.com/book/zh • Git Magic (English) – http://www-cs-students.stanford.edu/~blynn/gitmagic/ • Git Magic ( 繁體中文 ) – http://www-cs-students.stanford.edu/~blynn/gitmagic/intl/zh_tw/ • Git 教育訓練課程投影片 (2012) form ihower – http://ihower.tw/blog/archives/6696/ 29