SlideShare a Scribd company logo
Git walkthrough
@modsaid
Outline
● Source Control
● Git Basics
● Configuration
● Viewing history
● Undoing
● Aliases
● Tagging
● Branching
● Remotes
● Bare repos
● Hosting: Github, bitbucket, ...
● Git 2.0+
Version
Control
System
Centralized
Version
Control
System
Distributed
Version
Control
System
Git Basics
● Local Repo ( .git )
● Working directory
Git Basics - The 3 States
Git Basics
● git init
● git status
● git add
● git commit
● git reset
● git clone
● git mv
● git rm
● git blame
● git push
● git pull
Git Basics - committing
# Initializing a new repo
$ git init .
# Staging
$ git add .
$ git add -A
# committing
$ git commit -m “initial commit”
Git Basics - committing
$ git status
# diff (working vs staged)
$ git diff
# diff (staged vs committed)
$ git diff -s
# Stage and commit in one shot
$ git commit -a -m “direct staging and commit”
Git Configuration
● System
● User
● repo
/etc/gitconfig
~/.gitconfig or ~/.config/git/config
.git/config
Git Configuration
git config --system
git config --global
git config --local
Git Configuration
$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.
com
$ git config --global core.editor emacs
$ git config --list
$ git config user.name
Viewing History
$ git log
$ git log -p -2
$ git log --stat
$ git log --grep adding
$ git log --since=2.weeks
$ git log --Sfunction_name
$ git log --pretty=oneline
$ git log --pretty=format:"%h - %an, %ar : %s"
Git walkthrough
Viewing History
$ git log --pretty=format:"%ad %an : %s " --
date=short
$ git log --pretty=oneline --since=”2012-12-20”
--until=”2013-01-01” -5
$ git log --pretty=oneline | wc -l #no of commits
$ git log --pretty=format:%cd --date=short |
uniq | wc -l #no of working days
Viewing History
$ git shortlog
$ git shortlog -s | wc -l #no of devs
$ git shortlog -se # list of devs
#no of coding days
$ git log --pretty=format:”%ad” --date=short |
uniq | wc -l
Viewing History - mapping names
$ git shortlog -se | grep -i john
6 John Doe <john.doe@espace.com.eg>
10 John-Doe <john.doe@espace.com.eg>
4 John.Doe <john.doe@espace.com.eg>
$ vim .mailmap
name1 name2 name3 mail@example.com
name4 mail@example.com
$ git shortlog -se > .mailmap
Undoing
git commit --amend
# Changing commit message
$ git commit --amend -m “better commit message”
# Adding forgotten file
$ git commit -m 'initial commit'
$ git add forgotten_file
$ git commit --amend
Undoing
#Unstaging
$ git add .
$ git status
$ git reset HEAD benchmarks.rb
#dropping local commits <DANGER>
git reset --hard HEAD~3
Git Aliases
$ git config --global alias.co checkout
$ git config --global alias.ci commit
$ git config --global alias.st status
$ git config alias.showdevs 'shortlog -s'
$ git config --global alias.unstage 'reset HEAD
--'
Tagging
● Lightweight: pointer to specific commit
$ git tag before-optimization
● Annotated: full objects, checksummed,
contains tagger info, suitable for
releases
$ git tag -a v1.4 -m 'my version 1.4'
Tagging
#Tagging later
$ git tag -a v1.2 9fceb02
$ git show v1.2
$ git push origin v1.5
$ git push origin --tags
Branching
$ git branch #List current branches
$ git branch newone # create a new branch newone
$ git checkout newone # switch to newone branch
# create branch and switch in one step
$ git checkout -b newtwo
Branching
# Committing on master
Branching
$ git branch testing
Branching
Branching
$ git checkout testing
Branching
$ git commit -a -m “some change”
Branching
$ git checkout master
Branching
$ git commit -a -m “master commit”
Branching - Merging
$ git merge testing
# in case of conflicts (failed auto merge)
$ git mergetool
Branching - Merging
fast-forward
git merge feature
no fast-forward
git merge --no-ff feature
Remotes
# Listing remotes
$ git remote
$ git remote -v
# Adding a remote
$ git remote add [shortname] [url]
$ git remote show origin
Remotes
# Fetching updates
$ git fetch [remote-name]
$ git remote rename pb paul
$ git remote rm paul
Bare Repos
● git repo with no working directory
● The git server side
$ git init --bare .
# Cloning (backup)
$ git clone --bare git@github.com:modsaid/git-demo2.git
# Restoring
$ git push --mirror git@bitbucket.org:modsaid/git-demo2.git
Hosting: github, bitbucket
● Github: the most popular, free public repos
● Bitbucket: free private with limited
collaborators
● A lot others
Github
● Exploring repos
● Pull Requests
● Contribution to repos:
○ Fork
○ Fix/Add
○ Send pull request
https://help.github.com/articles/fork-a-repo/
Latest git
The latest git release today is 2.3.3
Installing the latest git (2.3)
$ sudo add-apt-repository ppa:git-core/ppa
$ sudo apt-get update
$ sudo apt-get install git
What’s new in Git 2.0
“From the point of view of end-users who are totally new to
Git, this release will give them the defaults that are vastly
improved compared to the older versions, but at the same
time, for existing users, this release is designed to be as
low-impact as possible as long as they have been following
recent releases along.”
● Better Defaults
what’s new? git push
pre git 2.0
● Default: matching
starting git 2.0
● Default: simple
git config push.default
● ( nothing | current | upstream | simple | matching )
what’s new? git add -u
pre git 2.0
● stage files in working directory
starting git 2.0
● stage files in the Repo Directory
what’s new? git diff -q
pre git 2.0
● valid option
starting git 2.0
● Removed
Do not display deleted files during git diff
what’s new?
● https://raw.githubusercontent.com/git/git/master/Documentation/RelNotes/2.0.0.txt
● https://raw.githubusercontent.com/git/git/master/Documentation/RelNotes/2.1.0.txt
● https://raw.githubusercontent.com/git/git/master/Documentation/RelNotes/2.2.0.txt
● https://raw.githubusercontent.com/git/git/master/Documentation/RelNotes/2.3.0.txt
Resources
● Pro Git, Second Edition
By: Scott Chacon; Ben Straub
Publisher: Apress
Pub. Date: November 19, 2014
● git help COMMAND (man pages)
● Git Recipes by BasayelSaid
Thank You

More Related Content

PDF
Git in 5 Minutes
PPTX
Get Good With Git
PDF
Gitosis on Mac OS X Server
PPTX
Git cli
PPTX
Introduction to GIT
PPTX
Git beyond basics
PDF
GIT: Content-addressable filesystem and Version Control System
Git in 5 Minutes
Get Good With Git
Gitosis on Mac OS X Server
Git cli
Introduction to GIT
Git beyond basics
GIT: Content-addressable filesystem and Version Control System

What's hot (20)

KEY
Clojure + MongoDB on Heroku
PPTX
Intro to Git DevOps Tally Presentation 101615
PPT
Learn Git Basics
PPTX
Understanding about git
PDF
GIT_GITHUB_2016_06_17
PDF
Git: An introduction of plumbing and porcelain commands
PPT
Basic git
PDF
Introducción a git y GitHub
PDF
Python_Session
PDF
Now i git it!!!
PDF
Nge-GIT (Belajar Git Bareng)
PPTX
PPTX
Git Memento of basic commands
PDF
Pengenalan Git
PDF
Brainly git basics workshop
ODP
Eat my data
PDF
Git it on (includes git hub)
PDF
GIT rozproszony system kontroli wersji
PPTX
Do you know GIT?
PDF
Clojure + MongoDB on Heroku
Intro to Git DevOps Tally Presentation 101615
Learn Git Basics
Understanding about git
GIT_GITHUB_2016_06_17
Git: An introduction of plumbing and porcelain commands
Basic git
Introducción a git y GitHub
Python_Session
Now i git it!!!
Nge-GIT (Belajar Git Bareng)
Git Memento of basic commands
Pengenalan Git
Brainly git basics workshop
Eat my data
Git it on (includes git hub)
GIT rozproszony system kontroli wersji
Do you know GIT?
Ad

Similar to Git walkthrough (20)

PPTX
An introduction to Git
PPTX
Introduction to Git and Github
KEY
Let's Git this Party Started: An Introduction to Git and GitHub
PPT
Introduction to Git
PPTX
git-and-bitbucket
PPT
Git presentation
PPTX
Git session Dropsolid.com
PDF
Git for beginners
PDF
GIT Basics
PDF
Advanced Git Tutorial
PPT
Introduction to git
PPTX
Learning Basic GIT Cmd
PPTX
sample.pptx
PPT
B4usolution git git-hub
PDF
Collaborative development with Git | Workshop
PPTX
Git and github
PPT
390a gitintro 12au
PPTX
Git and Github
PPT
Fundamentals and basics of Git and commands
PPTX
Git hub abduallah abu nada
An introduction to Git
Introduction to Git and Github
Let's Git this Party Started: An Introduction to Git and GitHub
Introduction to Git
git-and-bitbucket
Git presentation
Git session Dropsolid.com
Git for beginners
GIT Basics
Advanced Git Tutorial
Introduction to git
Learning Basic GIT Cmd
sample.pptx
B4usolution git git-hub
Collaborative development with Git | Workshop
Git and github
390a gitintro 12au
Git and Github
Fundamentals and basics of Git and commands
Git hub abduallah abu nada
Ad

More from Mahmoud Said (7)

ODP
IT Operations for Web Developers
ODP
Beginner walkthrough to git and github
PDF
Introduction to ZeroMQ - eSpace TechTalk
PDF
Linux Administration for Developers
PPT
ebda2, Business plan - Omar Shawky
PDF
Google ebda2 - eCommerce - Souq.com
PPTX
Entrepreneurship 101
IT Operations for Web Developers
Beginner walkthrough to git and github
Introduction to ZeroMQ - eSpace TechTalk
Linux Administration for Developers
ebda2, Business plan - Omar Shawky
Google ebda2 - eCommerce - Souq.com
Entrepreneurship 101

Recently uploaded (20)

PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPT
Teaching material agriculture food technology
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Electronic commerce courselecture one. Pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Machine learning based COVID-19 study performance prediction
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
Cloud computing and distributed systems.
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Chapter 3 Spatial Domain Image Processing.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Understanding_Digital_Forensics_Presentation.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
Teaching material agriculture food technology
“AI and Expert System Decision Support & Business Intelligence Systems”
Diabetes mellitus diagnosis method based random forest with bat algorithm
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
MYSQL Presentation for SQL database connectivity
Network Security Unit 5.pdf for BCA BBA.
Electronic commerce courselecture one. Pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Machine learning based COVID-19 study performance prediction
Review of recent advances in non-invasive hemoglobin estimation
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Programs and apps: productivity, graphics, security and other tools
Cloud computing and distributed systems.
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Spectral efficient network and resource selection model in 5G networks
Chapter 3 Spatial Domain Image Processing.pdf

Git walkthrough

  • 2. Outline ● Source Control ● Git Basics ● Configuration ● Viewing history ● Undoing ● Aliases ● Tagging ● Branching ● Remotes ● Bare repos ● Hosting: Github, bitbucket, ... ● Git 2.0+
  • 6. Git Basics ● Local Repo ( .git ) ● Working directory
  • 7. Git Basics - The 3 States
  • 8. Git Basics ● git init ● git status ● git add ● git commit ● git reset ● git clone ● git mv ● git rm ● git blame ● git push ● git pull
  • 9. Git Basics - committing # Initializing a new repo $ git init . # Staging $ git add . $ git add -A # committing $ git commit -m “initial commit”
  • 10. Git Basics - committing $ git status # diff (working vs staged) $ git diff # diff (staged vs committed) $ git diff -s # Stage and commit in one shot $ git commit -a -m “direct staging and commit”
  • 11. Git Configuration ● System ● User ● repo /etc/gitconfig ~/.gitconfig or ~/.config/git/config .git/config
  • 12. Git Configuration git config --system git config --global git config --local
  • 13. Git Configuration $ git config --global user.name "John Doe" $ git config --global user.email johndoe@example. com $ git config --global core.editor emacs $ git config --list $ git config user.name
  • 14. Viewing History $ git log $ git log -p -2 $ git log --stat $ git log --grep adding $ git log --since=2.weeks $ git log --Sfunction_name $ git log --pretty=oneline $ git log --pretty=format:"%h - %an, %ar : %s"
  • 16. Viewing History $ git log --pretty=format:"%ad %an : %s " -- date=short $ git log --pretty=oneline --since=”2012-12-20” --until=”2013-01-01” -5 $ git log --pretty=oneline | wc -l #no of commits $ git log --pretty=format:%cd --date=short | uniq | wc -l #no of working days
  • 17. Viewing History $ git shortlog $ git shortlog -s | wc -l #no of devs $ git shortlog -se # list of devs #no of coding days $ git log --pretty=format:”%ad” --date=short | uniq | wc -l
  • 18. Viewing History - mapping names $ git shortlog -se | grep -i john 6 John Doe <john.doe@espace.com.eg> 10 John-Doe <john.doe@espace.com.eg> 4 John.Doe <john.doe@espace.com.eg> $ vim .mailmap name1 name2 name3 mail@example.com name4 mail@example.com $ git shortlog -se > .mailmap
  • 19. Undoing git commit --amend # Changing commit message $ git commit --amend -m “better commit message” # Adding forgotten file $ git commit -m 'initial commit' $ git add forgotten_file $ git commit --amend
  • 20. Undoing #Unstaging $ git add . $ git status $ git reset HEAD benchmarks.rb #dropping local commits <DANGER> git reset --hard HEAD~3
  • 21. Git Aliases $ git config --global alias.co checkout $ git config --global alias.ci commit $ git config --global alias.st status $ git config alias.showdevs 'shortlog -s' $ git config --global alias.unstage 'reset HEAD --'
  • 22. Tagging ● Lightweight: pointer to specific commit $ git tag before-optimization ● Annotated: full objects, checksummed, contains tagger info, suitable for releases $ git tag -a v1.4 -m 'my version 1.4'
  • 23. Tagging #Tagging later $ git tag -a v1.2 9fceb02 $ git show v1.2 $ git push origin v1.5 $ git push origin --tags
  • 24. Branching $ git branch #List current branches $ git branch newone # create a new branch newone $ git checkout newone # switch to newone branch # create branch and switch in one step $ git checkout -b newtwo
  • 29. Branching $ git commit -a -m “some change”
  • 31. Branching $ git commit -a -m “master commit”
  • 32. Branching - Merging $ git merge testing # in case of conflicts (failed auto merge) $ git mergetool
  • 33. Branching - Merging fast-forward git merge feature no fast-forward git merge --no-ff feature
  • 34. Remotes # Listing remotes $ git remote $ git remote -v # Adding a remote $ git remote add [shortname] [url] $ git remote show origin
  • 35. Remotes # Fetching updates $ git fetch [remote-name] $ git remote rename pb paul $ git remote rm paul
  • 36. Bare Repos ● git repo with no working directory ● The git server side $ git init --bare . # Cloning (backup) $ git clone --bare git@github.com:modsaid/git-demo2.git # Restoring $ git push --mirror git@bitbucket.org:modsaid/git-demo2.git
  • 37. Hosting: github, bitbucket ● Github: the most popular, free public repos ● Bitbucket: free private with limited collaborators ● A lot others
  • 38. Github ● Exploring repos ● Pull Requests ● Contribution to repos: ○ Fork ○ Fix/Add ○ Send pull request https://help.github.com/articles/fork-a-repo/
  • 39. Latest git The latest git release today is 2.3.3
  • 40. Installing the latest git (2.3) $ sudo add-apt-repository ppa:git-core/ppa $ sudo apt-get update $ sudo apt-get install git
  • 41. What’s new in Git 2.0 “From the point of view of end-users who are totally new to Git, this release will give them the defaults that are vastly improved compared to the older versions, but at the same time, for existing users, this release is designed to be as low-impact as possible as long as they have been following recent releases along.” ● Better Defaults
  • 42. what’s new? git push pre git 2.0 ● Default: matching starting git 2.0 ● Default: simple git config push.default ● ( nothing | current | upstream | simple | matching )
  • 43. what’s new? git add -u pre git 2.0 ● stage files in working directory starting git 2.0 ● stage files in the Repo Directory
  • 44. what’s new? git diff -q pre git 2.0 ● valid option starting git 2.0 ● Removed Do not display deleted files during git diff
  • 45. what’s new? ● https://raw.githubusercontent.com/git/git/master/Documentation/RelNotes/2.0.0.txt ● https://raw.githubusercontent.com/git/git/master/Documentation/RelNotes/2.1.0.txt ● https://raw.githubusercontent.com/git/git/master/Documentation/RelNotes/2.2.0.txt ● https://raw.githubusercontent.com/git/git/master/Documentation/RelNotes/2.3.0.txt
  • 46. Resources ● Pro Git, Second Edition By: Scott Chacon; Ben Straub Publisher: Apress Pub. Date: November 19, 2014 ● git help COMMAND (man pages) ● Git Recipes by BasayelSaid