SlideShare a Scribd company logo
1 of 22
Download to read offline
Git	
  In	
  a	
  Nutshell	
  
By: Pranesh Vittal CG
http://in.linkedin.com/in/praneshvittal
Key	
  takeaways	
  from	
  this	
  session	
  
•  Differences	
  between	
  Centralized	
  &	
  Distributed	
  Version	
  
Control	
  System.	
  
•  Unlearning	
  some	
  of	
  the	
  concepts	
  from	
  CVS	
  /	
  SVN	
  World.	
  
•  What	
  is	
  Git?	
  
•  Git	
  IniEalizaEon	
  
•  Git	
  Config	
  /	
  Git	
  Ignore	
  
•  Most	
  Frequently	
  Used	
  Git	
  Commands	
  
•  Merging	
  Conflicts	
  
•  Git	
  Mergetool	
  
•  Git	
  Help	
  
•  Git	
  CollaboraEon	
  Methods	
  
•  What	
  is	
  a	
  PR	
  and	
  the	
  steps	
  associated	
  with	
  it?	
  
What	
  is	
  SCM	
  ???	
  
SCM	
  -­‐>	
  Source	
  Control	
  Management	
  
	
  
VCS	
  -­‐>	
  Version	
  Control	
  System	
  
	
  
Centralized	
  VCS	
  
•  CVS,	
  Perforce,	
  SVN	
  
	
  
Distributed	
  VCS	
  
•  Git,	
  Mercurial	
  
	
  
Unlearning	
  CVS	
  &	
  SVN	
  
git	
  equivalent	
  for	
  “svn	
  checkout	
  url”	
  is	
  “git	
  clone	
  url”	
  
git	
  equivalent	
  for	
  “svn	
  update”	
  is	
  “git	
  pull”	
  
git	
  equivalent	
  for	
  “svn	
  commit”	
  is	
  “git	
  commit	
  -­‐a	
  &&	
  git	
  
push”	
  
	
  
Some	
  of	
  the	
  features	
  available	
  in	
  Git:	
  
	
  
•  Cheap	
  &	
  Easy	
  Branching.	
  
•  Disconnected	
  Use	
  wherein	
  the	
  user	
  is	
  not	
  connected	
  to	
  
the	
  Network.	
  
•  Staging	
  just	
  what	
  is	
  required	
  for	
  a	
  parEcular	
  feature.	
  
•  BeYer	
  collaboraEon	
  with	
  other	
  developers.	
  
What	
  is	
  Git	
  ???	
  
•  Distributed	
  VCS	
  
•  Everything	
  is	
  check-­‐summed	
  (40	
  characters	
  sha-­‐1	
  hash.	
  Hexadecimal	
  unique	
  value	
  
calculated	
  based	
  on	
  author’s	
  name	
  &	
  email-­‐id,	
  contents	
  of	
  the	
  file	
  &	
  few	
  other	
  
parameters).	
  
•  Snapshots	
  and	
  not	
  differences.	
  
•  Everything	
  related	
  to	
  the	
  git	
  project	
  can	
  be	
  found	
  in	
  .git	
  directory	
  at	
  the	
  root	
  level	
  of	
  
the	
  project.	
  
	
  
	
  
What	
  is	
  Git	
  ???	
  
•  Nearly	
  Every	
  AcEon	
  Is	
  Local.	
  
•  Consists	
  of	
  following	
  areas:	
  
–  Working	
  Directory	
  
–  Staging	
  Area	
  
–  Git	
  Repository	
  
	
  
In	
  a	
  nut	
  shell	
  
Git	
  Config	
  
•  git	
  config	
  -­‐-­‐global	
  user.name	
  “Pranesh	
  ViYal”	
  
•  git	
  config	
  -­‐-­‐global	
  user.email	
  “me@email.com”	
  
	
  
OR	
  	
  
•  ~/.gitconfig	
  
[user]	
  
	
  name	
  =	
  Pranesh	
  ViYal	
  
	
  email	
  =	
  me@email.com	
  
[credenEal]	
  
	
  helper	
  =	
  cache	
  -­‐-­‐Emeout=3600	
  
[core]	
  
	
  editor	
  =	
  vim	
  
[merge]	
  
	
  tool	
  =	
  vimdiff	
  
[alias]	
  
	
  b	
  =	
  branch	
  
	
  
•  More	
  such	
  examples	
  :	
  
hYps://gist.github.com/pksunkara/988716	
  	
  
	
  
.giAgnore	
  
#	
  Compiled	
  source	
  #	
  
*.com	
  
*.class	
  
*.dll	
  
*.exe	
  
*.o#	
  Logs	
  and	
  databases	
  #	
  
*.log	
  
*.sql	
  
*.sqlite	
  
	
  	
  
#	
  OS	
  generated	
  files	
  #	
  
.DS_Store*	
  
ehthumbs.db	
  
Icon?	
  
Thumbs.db	
  
	
  
	
  	
  
*.so	
  
	
  	
  
#	
  Temporary	
  files	
  #	
  
*.swp	
  
*.swo	
  
*~	
  
	
  	
  
#	
  Packages	
  #	
  
*.7z	
  
*.dmg	
  
*.gz	
  
*.iso	
  
*.jar	
  
*.rar	
  
*.tar	
  
*.zip	
  
	
  	
  
	
  
https://github.com/sethvargo/chefspec/blob/master/.gitignore
Most	
  Frequently	
  Used	
  OperaAons	
  
init	
  
add	
  
branch	
  
commit	
  
checkout	
  
diff	
  
fetch	
  
log	
  
merge	
  
prune	
  
push	
  
pull	
  
rebase	
  
reset	
  
remote	
  
status	
  
stash	
  
show	
  
tag	
  
Most	
  Frequently	
  Used	
  Commands	
  
•  git	
  init	
  (Arer	
  creaEng	
  the	
  directory	
  and	
  cd	
  into	
  into	
  it).	
  
•  git	
  clone	
  <git-­‐repo>	
  
•  git	
  add	
  .	
  (Add	
  untracked	
  files)	
  
•  git	
  status	
  (Current	
  status	
  of	
  the	
  local	
  git	
  directory).	
  
•  git	
  commit	
  -­‐m	
  “First	
  Commit	
  of	
  the	
  file.”	
  (Commit	
  the	
  
files).	
  
•  git	
  push	
  <remote-­‐short-­‐name>	
  <branch-­‐name>	
  (Push	
  the	
  
changes	
  to	
  the	
  repository).	
  
•  git	
  log	
  (Log	
  of	
  checkins	
  performed	
  on	
  the	
  branch).	
  
•  git	
  log	
  -­‐p	
  -­‐2	
  (Details	
  of	
  the	
  last	
  2	
  commits).	
  
•  git	
  log	
  -­‐-­‐preYy=oneline	
  (Log	
  info	
  in	
  oneline	
  format).	
  
	
  
*remote-­‐short-­‐name	
  -­‐	
  default	
  value	
  is	
  origin	
  
	
  
Most	
  Frequently	
  Used	
  Commands	
  
•  git	
  diff	
  <old-­‐tag>	
  <new-­‐tag>	
  (Show	
  changes	
  between	
  commits,	
  
commit	
  and	
  working	
  tree	
  etc...)	
  
•  git	
  diff	
  -­‐-­‐cached	
  (Diff	
  between	
  the	
  working	
  and	
  the	
  staged	
  
area)	
  
•  git	
  diff	
  HEAD	
  (Diff	
  between	
  the	
  working	
  and	
  the	
  repository)	
  
•  git	
  rm	
  -­‐f	
  <filename>	
  (Delete	
  the	
  file	
  from	
  git).	
  
•  git	
  reset	
  HEAD	
  <file-­‐name>	
  (To	
  reset	
  a	
  file	
  that	
  has	
  been	
  
staged	
  but	
  not	
  checked-­‐in).	
  
•  git	
  checkout	
  <file-­‐name>	
  (To	
  reset	
  a	
  file	
  that	
  has	
  been	
  been	
  
modified	
  in	
  working	
  area).	
  
•  git	
  stash	
  (Temporary	
  check-­‐in	
  while	
  switching	
  between	
  
branches).	
  
•  git	
  stash	
  list	
  (List	
  of	
  stash	
  items).	
  
•  git	
  stash	
  apply	
  @stash@{n}	
  (Add	
  the	
  stashed	
  items	
  back	
  to	
  the	
  
branch).	
  
	
  
	
  
Most	
  Frequently	
  Used	
  Commands	
  
•  git	
  branch	
  (List	
  the	
  branches	
  on	
  the	
  local	
  repository.	
  Can	
  be	
  found	
  
in	
  .git/refs/heads/).	
  
•  git	
  branch	
  new-­‐branch	
  (Create	
  new	
  branch).	
  
•  git	
  checkout	
  new-­‐branch	
  (Switch	
  to	
  the	
  new	
  branch).	
  
•  git	
  checkout	
  -­‐b	
  <new-­‐branch>	
  <remote-­‐short-­‐name>/<branch-­‐
name>	
  (To	
  check	
  out	
  the	
  new	
  branch	
  from	
  the	
  repository).	
  	
  
•  git	
  diff	
  (Diff	
  of	
  the	
  current	
  state	
  with	
  the	
  repository).	
  
•  git	
  tag	
  <tag-­‐name>	
  (To	
  create	
  a	
  tag).	
  
•  git	
  checkout	
  -­‐-­‐track	
  <remote>/<branch>	
  
•  git	
  branch	
  -­‐r	
  (List	
  the	
  branches	
  on	
  the	
  remote	
  repository.	
  Can	
  be	
  
found	
  in	
  .git/refs/remotes/).	
  
•  git	
  branch	
  -­‐v	
  (List	
  out	
  the	
  recent	
  commits	
  performed	
  in	
  all	
  the	
  
branches)	
  
Most	
  Frequently	
  Used	
  Commands	
  
•  git	
  remote	
  (Display	
  list	
  of	
  remote	
  repositories).	
  
•  git	
  remote	
  add	
  <remote-­‐short-­‐name>	
  (To	
  create	
  a	
  remote	
  
repository).	
  
•  git	
  remote	
  fetch	
  <remote-­‐short-­‐name>	
  (To	
  fetch	
  the	
  changes	
  from	
  
other	
  repository.)	
  
•  git	
  fetch	
  <remote-­‐short-­‐name>	
  (To	
  get	
  files	
  from	
  remote	
  projects).	
  
•  git	
  pull	
  <remote-­‐short-­‐name>	
  <branch-­‐name>	
  (AutomaEcally	
  fetch	
  
and	
  then	
  merge	
  a	
  remote	
  branch	
  into	
  your	
  current	
  branch).	
  
•  git	
  merge	
  <branch-­‐to-­‐be-­‐merged>	
  (To	
  merge	
  the	
  changes.	
  Before	
  
execuEng	
  this,	
  make	
  sure	
  that	
  you	
  are	
  in	
  the	
  target	
  branch).	
  
•  git	
  rebase	
  <branch-­‐name>	
  (FuncEons	
  very	
  similar	
  to	
  merge,	
  but	
  good	
  
at	
  keeping	
  the	
  history	
  of	
  changes	
  in	
  a	
  clean	
  way.)	
  
•  git	
  branch	
  -­‐d	
  <branch-­‐name>	
  
•  git	
  reset	
  -­‐-­‐hard	
  HEAD	
  (When	
  SHIT	
  happens	
  and	
  you	
  messed	
  with	
  too	
  
many	
  merges	
  and	
  you	
  don’t	
  care	
  about	
  the	
  changes	
  you	
  did).	
  
	
  
Merging	
  Conflicts	
  
git	
  merge	
  <branch-­‐to-­‐be-­‐merged>	
  
Auto-­‐merging	
  index.html	
  
CONFLICT	
  (content):	
  Merge	
  conflict	
  in	
  index.html	
  
AutomaEc	
  merge	
  failed;	
  fix	
  conflicts	
  and	
  then	
  commit	
  the	
  result.	
  
	
  
git	
  status	
  
You	
  have	
  unmerged	
  paths.	
  
	
  
<<<<<<<	
  HEAD:index.html	
  
<div	
  id="footer">contact	
  :	
  email.support@github.com</div>	
  
=======	
  
<div	
  id="footer">	
  
	
  please	
  contact	
  us	
  at	
  support@github.com	
  
</div>	
  
>>>>>>>	
  iss53:index.html	
  
	
  
git	
  mergetool:	
  	
  
Git	
  mergetool	
  
Help	
  !!!	
  
git	
  help	
  <command>	
  
git	
  help	
  commit	
  
git	
  help	
  branch	
  
git	
  help	
  	
  
Git	
  Pull	
  Requests	
  
What	
  is	
  a	
  pull	
  request?	
  
	
  
Most	
  important	
  step	
  wherein	
  a	
  collaborator	
  
sends	
  across	
  his	
  changes	
  to	
  be	
  merged	
  into	
  
the	
  master	
  branch.	
  The	
  changes	
  will	
  be	
  pulled	
  
by	
  the	
  commiYer	
  and	
  merged	
  into	
  the	
  master.	
  
	
  
Popular	
  CollaboraAve	
  Development	
  Methods	
  
•  Fork	
  &	
  Pull	
  (Followed	
  in	
  most	
  of	
  the	
  open	
  
source	
  projects	
  on	
  GitHub).	
  
•  Shared	
  Repository	
  Model	
  (The	
  one	
  followed	
  
in	
  in	
  house	
  projects)	
  
Some	
  of	
  the	
  popular	
  models	
  
References	
  
hYp://nvie.com/posts/a-­‐successful-­‐git-­‐branching-­‐model/	
  	
  
hYp://scoYchacon.com/2011/08/31/github-­‐flow.html	
  	
  
hYp://git-­‐scm.com/doc	
  	
  
hYp://cleanercode.com/introducEon-­‐to-­‐git-­‐talk/introducEon-­‐to-­‐git.pdf	
  	
  
hYp://nvie.com/files/Git-­‐branching-­‐model.pdf	
  	
  
Q & A

More Related Content

What's hot

What's hot (20)

Git basic
Git basicGit basic
Git basic
 
Git introduction workshop for scientists
Git introduction workshop for scientists Git introduction workshop for scientists
Git introduction workshop for scientists
 
Gitting out of trouble
Gitting out of troubleGitting out of trouble
Gitting out of trouble
 
Grokking opensource with github
Grokking opensource with githubGrokking opensource with github
Grokking opensource with github
 
Git for beginners
Git for beginnersGit for beginners
Git for beginners
 
Git training v10
Git training v10Git training v10
Git training v10
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
Git-ing out of your git messes
Git-ing out of  your git messesGit-ing out of  your git messes
Git-ing out of your git messes
 
Git Tutorial I
Git Tutorial IGit Tutorial I
Git Tutorial I
 
Git learning
Git learningGit learning
Git learning
 
Git commands
Git commandsGit commands
Git commands
 
Git real slides
Git real slidesGit real slides
Git real slides
 
Git Started With Git
Git Started With GitGit Started With Git
Git Started With Git
 
Introduction To Git
Introduction To GitIntroduction To Git
Introduction To Git
 
Introduction to Git and Github
Introduction to Git and GithubIntroduction to Git and Github
Introduction to Git and Github
 
An Introduction to Git
An Introduction to GitAn Introduction to Git
An Introduction to Git
 
Git 101
Git 101Git 101
Git 101
 
Basic principles of Git
Basic principles of GitBasic principles of Git
Basic principles of Git
 
Git - An Introduction
Git - An IntroductionGit - An Introduction
Git - An Introduction
 
Git 101 for Beginners
Git 101 for Beginners Git 101 for Beginners
Git 101 for Beginners
 

Similar to Git in a nutshell

Gitting the Most From Git
Gitting the Most From GitGitting the Most From Git
Gitting the Most From Git
Chris Miller
 
Beginner's Guide to Version Control with Git
Beginner's Guide to Version Control with GitBeginner's Guide to Version Control with Git
Beginner's Guide to Version Control with Git
Robert Lee-Cann
 

Similar to Git in a nutshell (20)

An introduction to Git
An introduction to GitAn introduction to Git
An introduction to Git
 
Introduction into Git
Introduction into GitIntroduction into Git
Introduction into Git
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github
 
Learning Basic GIT Cmd
Learning Basic GIT CmdLearning Basic GIT Cmd
Learning Basic GIT Cmd
 
Git Tech Talk
Git  Tech TalkGit  Tech Talk
Git Tech Talk
 
Git session Dropsolid.com
Git session Dropsolid.comGit session Dropsolid.com
Git session Dropsolid.com
 
Introduction To Git Workshop
Introduction To Git WorkshopIntroduction To Git Workshop
Introduction To Git Workshop
 
Gitting the Most From Git
Gitting the Most From GitGitting the Most From Git
Gitting the Most From Git
 
Introduction git
Introduction gitIntroduction git
Introduction git
 
Beginner's Guide to Version Control with Git
Beginner's Guide to Version Control with GitBeginner's Guide to Version Control with Git
Beginner's Guide to Version Control with Git
 
Git
Git Git
Git
 
Demystifying Git
Demystifying GitDemystifying Git
Demystifying Git
 
Demystifying Git
Demystifying GitDemystifying Git
Demystifying Git
 
Git github
Git githubGit github
Git github
 
Git
GitGit
Git
 
Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notes
 
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
 
Git and git workflow best practice
Git and git workflow best practiceGit and git workflow best practice
Git and git workflow best practice
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITM
 
Git hub
Git hubGit hub
Git hub
 

Recently uploaded

Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
drm1699
 

Recently uploaded (20)

[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
 
Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024
 
Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
 
Abortion Pill Prices Mthatha (@](+27832195400*)[ 🏥 Women's Abortion Clinic In...
Abortion Pill Prices Mthatha (@](+27832195400*)[ 🏥 Women's Abortion Clinic In...Abortion Pill Prices Mthatha (@](+27832195400*)[ 🏥 Women's Abortion Clinic In...
Abortion Pill Prices Mthatha (@](+27832195400*)[ 🏥 Women's Abortion Clinic In...
 
Abortion Pill Prices Turfloop ](+27832195400*)[ 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Turfloop ](+27832195400*)[ 🏥 Women's Abortion Clinic in ...Abortion Pill Prices Turfloop ](+27832195400*)[ 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Turfloop ](+27832195400*)[ 🏥 Women's Abortion Clinic in ...
 
Prompt Engineering - an Art, a Science, or your next Job Title?
Prompt Engineering - an Art, a Science, or your next Job Title?Prompt Engineering - an Art, a Science, or your next Job Title?
Prompt Engineering - an Art, a Science, or your next Job Title?
 
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdfThe Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
 
Optimizing Operations by Aligning Resources with Strategic Objectives Using O...
Optimizing Operations by Aligning Resources with Strategic Objectives Using O...Optimizing Operations by Aligning Resources with Strategic Objectives Using O...
Optimizing Operations by Aligning Resources with Strategic Objectives Using O...
 
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
 
Food Delivery Business App Development Guide 2024
Food Delivery Business App Development Guide 2024Food Delivery Business App Development Guide 2024
Food Delivery Business App Development Guide 2024
 
Transformer Neural Network Use Cases with Links
Transformer Neural Network Use Cases with LinksTransformer Neural Network Use Cases with Links
Transformer Neural Network Use Cases with Links
 
architecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdfarchitecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdf
 
Microsoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdfMicrosoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdf
 
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
 
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit MilanWorkshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
 
Software Engineering - Introduction + Process Models + Requirements Engineering
Software Engineering - Introduction + Process Models + Requirements EngineeringSoftware Engineering - Introduction + Process Models + Requirements Engineering
Software Engineering - Introduction + Process Models + Requirements Engineering
 
GraphSummit Milan - Visione e roadmap del prodotto Neo4j
GraphSummit Milan - Visione e roadmap del prodotto Neo4jGraphSummit Milan - Visione e roadmap del prodotto Neo4j
GraphSummit Milan - Visione e roadmap del prodotto Neo4j
 
Auto Affiliate AI Earns First Commission in 3 Hours..pdf
Auto Affiliate  AI Earns First Commission in 3 Hours..pdfAuto Affiliate  AI Earns First Commission in 3 Hours..pdf
Auto Affiliate AI Earns First Commission in 3 Hours..pdf
 
Novo Nordisk: When Knowledge Graphs meet LLMs
Novo Nordisk: When Knowledge Graphs meet LLMsNovo Nordisk: When Knowledge Graphs meet LLMs
Novo Nordisk: When Knowledge Graphs meet LLMs
 
CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...
CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...
CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...
 

Git in a nutshell

  • 1. Git  In  a  Nutshell   By: Pranesh Vittal CG http://in.linkedin.com/in/praneshvittal
  • 2. Key  takeaways  from  this  session   •  Differences  between  Centralized  &  Distributed  Version   Control  System.   •  Unlearning  some  of  the  concepts  from  CVS  /  SVN  World.   •  What  is  Git?   •  Git  IniEalizaEon   •  Git  Config  /  Git  Ignore   •  Most  Frequently  Used  Git  Commands   •  Merging  Conflicts   •  Git  Mergetool   •  Git  Help   •  Git  CollaboraEon  Methods   •  What  is  a  PR  and  the  steps  associated  with  it?  
  • 3. What  is  SCM  ???   SCM  -­‐>  Source  Control  Management     VCS  -­‐>  Version  Control  System     Centralized  VCS   •  CVS,  Perforce,  SVN     Distributed  VCS   •  Git,  Mercurial    
  • 4. Unlearning  CVS  &  SVN   git  equivalent  for  “svn  checkout  url”  is  “git  clone  url”   git  equivalent  for  “svn  update”  is  “git  pull”   git  equivalent  for  “svn  commit”  is  “git  commit  -­‐a  &&  git   push”     Some  of  the  features  available  in  Git:     •  Cheap  &  Easy  Branching.   •  Disconnected  Use  wherein  the  user  is  not  connected  to   the  Network.   •  Staging  just  what  is  required  for  a  parEcular  feature.   •  BeYer  collaboraEon  with  other  developers.  
  • 5. What  is  Git  ???   •  Distributed  VCS   •  Everything  is  check-­‐summed  (40  characters  sha-­‐1  hash.  Hexadecimal  unique  value   calculated  based  on  author’s  name  &  email-­‐id,  contents  of  the  file  &  few  other   parameters).   •  Snapshots  and  not  differences.   •  Everything  related  to  the  git  project  can  be  found  in  .git  directory  at  the  root  level  of   the  project.      
  • 6. What  is  Git  ???   •  Nearly  Every  AcEon  Is  Local.   •  Consists  of  following  areas:   –  Working  Directory   –  Staging  Area   –  Git  Repository    
  • 7. In  a  nut  shell  
  • 8. Git  Config   •  git  config  -­‐-­‐global  user.name  “Pranesh  ViYal”   •  git  config  -­‐-­‐global  user.email  “me@email.com”     OR     •  ~/.gitconfig   [user]    name  =  Pranesh  ViYal    email  =  me@email.com   [credenEal]    helper  =  cache  -­‐-­‐Emeout=3600   [core]    editor  =  vim   [merge]    tool  =  vimdiff   [alias]    b  =  branch     •  More  such  examples  :   hYps://gist.github.com/pksunkara/988716      
  • 9. .giAgnore   #  Compiled  source  #   *.com   *.class   *.dll   *.exe   *.o#  Logs  and  databases  #   *.log   *.sql   *.sqlite       #  OS  generated  files  #   .DS_Store*   ehthumbs.db   Icon?   Thumbs.db         *.so       #  Temporary  files  #   *.swp   *.swo   *~       #  Packages  #   *.7z   *.dmg   *.gz   *.iso   *.jar   *.rar   *.tar   *.zip         https://github.com/sethvargo/chefspec/blob/master/.gitignore
  • 10. Most  Frequently  Used  OperaAons   init   add   branch   commit   checkout   diff   fetch   log   merge   prune   push   pull   rebase   reset   remote   status   stash   show   tag  
  • 11. Most  Frequently  Used  Commands   •  git  init  (Arer  creaEng  the  directory  and  cd  into  into  it).   •  git  clone  <git-­‐repo>   •  git  add  .  (Add  untracked  files)   •  git  status  (Current  status  of  the  local  git  directory).   •  git  commit  -­‐m  “First  Commit  of  the  file.”  (Commit  the   files).   •  git  push  <remote-­‐short-­‐name>  <branch-­‐name>  (Push  the   changes  to  the  repository).   •  git  log  (Log  of  checkins  performed  on  the  branch).   •  git  log  -­‐p  -­‐2  (Details  of  the  last  2  commits).   •  git  log  -­‐-­‐preYy=oneline  (Log  info  in  oneline  format).     *remote-­‐short-­‐name  -­‐  default  value  is  origin    
  • 12. Most  Frequently  Used  Commands   •  git  diff  <old-­‐tag>  <new-­‐tag>  (Show  changes  between  commits,   commit  and  working  tree  etc...)   •  git  diff  -­‐-­‐cached  (Diff  between  the  working  and  the  staged   area)   •  git  diff  HEAD  (Diff  between  the  working  and  the  repository)   •  git  rm  -­‐f  <filename>  (Delete  the  file  from  git).   •  git  reset  HEAD  <file-­‐name>  (To  reset  a  file  that  has  been   staged  but  not  checked-­‐in).   •  git  checkout  <file-­‐name>  (To  reset  a  file  that  has  been  been   modified  in  working  area).   •  git  stash  (Temporary  check-­‐in  while  switching  between   branches).   •  git  stash  list  (List  of  stash  items).   •  git  stash  apply  @stash@{n}  (Add  the  stashed  items  back  to  the   branch).      
  • 13. Most  Frequently  Used  Commands   •  git  branch  (List  the  branches  on  the  local  repository.  Can  be  found   in  .git/refs/heads/).   •  git  branch  new-­‐branch  (Create  new  branch).   •  git  checkout  new-­‐branch  (Switch  to  the  new  branch).   •  git  checkout  -­‐b  <new-­‐branch>  <remote-­‐short-­‐name>/<branch-­‐ name>  (To  check  out  the  new  branch  from  the  repository).     •  git  diff  (Diff  of  the  current  state  with  the  repository).   •  git  tag  <tag-­‐name>  (To  create  a  tag).   •  git  checkout  -­‐-­‐track  <remote>/<branch>   •  git  branch  -­‐r  (List  the  branches  on  the  remote  repository.  Can  be   found  in  .git/refs/remotes/).   •  git  branch  -­‐v  (List  out  the  recent  commits  performed  in  all  the   branches)  
  • 14. Most  Frequently  Used  Commands   •  git  remote  (Display  list  of  remote  repositories).   •  git  remote  add  <remote-­‐short-­‐name>  (To  create  a  remote   repository).   •  git  remote  fetch  <remote-­‐short-­‐name>  (To  fetch  the  changes  from   other  repository.)   •  git  fetch  <remote-­‐short-­‐name>  (To  get  files  from  remote  projects).   •  git  pull  <remote-­‐short-­‐name>  <branch-­‐name>  (AutomaEcally  fetch   and  then  merge  a  remote  branch  into  your  current  branch).   •  git  merge  <branch-­‐to-­‐be-­‐merged>  (To  merge  the  changes.  Before   execuEng  this,  make  sure  that  you  are  in  the  target  branch).   •  git  rebase  <branch-­‐name>  (FuncEons  very  similar  to  merge,  but  good   at  keeping  the  history  of  changes  in  a  clean  way.)   •  git  branch  -­‐d  <branch-­‐name>   •  git  reset  -­‐-­‐hard  HEAD  (When  SHIT  happens  and  you  messed  with  too   many  merges  and  you  don’t  care  about  the  changes  you  did).    
  • 15. Merging  Conflicts   git  merge  <branch-­‐to-­‐be-­‐merged>   Auto-­‐merging  index.html   CONFLICT  (content):  Merge  conflict  in  index.html   AutomaEc  merge  failed;  fix  conflicts  and  then  commit  the  result.     git  status   You  have  unmerged  paths.     <<<<<<<  HEAD:index.html   <div  id="footer">contact  :  email.support@github.com</div>   =======   <div  id="footer">    please  contact  us  at  support@github.com   </div>   >>>>>>>  iss53:index.html     git  mergetool:    
  • 17. Help  !!!   git  help  <command>   git  help  commit   git  help  branch   git  help    
  • 18. Git  Pull  Requests   What  is  a  pull  request?     Most  important  step  wherein  a  collaborator   sends  across  his  changes  to  be  merged  into   the  master  branch.  The  changes  will  be  pulled   by  the  commiYer  and  merged  into  the  master.    
  • 19. Popular  CollaboraAve  Development  Methods   •  Fork  &  Pull  (Followed  in  most  of  the  open   source  projects  on  GitHub).   •  Shared  Repository  Model  (The  one  followed   in  in  house  projects)  
  • 20. Some  of  the  popular  models  
  • 21. References   hYp://nvie.com/posts/a-­‐successful-­‐git-­‐branching-­‐model/     hYp://scoYchacon.com/2011/08/31/github-­‐flow.html     hYp://git-­‐scm.com/doc     hYp://cleanercode.com/introducEon-­‐to-­‐git-­‐talk/introducEon-­‐to-­‐git.pdf     hYp://nvie.com/files/Git-­‐branching-­‐model.pdf    
  • 22. Q & A