princeton jug git_github

31
Intro to Working with GIT and GitHub By Yakov Fain and Viktor Gamov Farata Systems www.faratasystems.com

Upload: yakov-fain

Post on 10-May-2015

664 views

Category:

Technology


0 download

DESCRIPTION

Intro to working with Git and GitHub

TRANSCRIPT

Page 1: Princeton jug git_github

Intro  to  Working  with  GIT  and  GitHub  

By  Yakov  Fain  and  Viktor  Gamov  Farata  Systems    

www.faratasystems.com  

Page 2: Princeton jug git_github

Centralized  file  repositories  

•  SVN  •  CVS  •  TFS  •  Perforce  •  …  

www.faratasystems.com  

Remote  Server  a.k.a.  repository  a.k.a.  repo    

Mary  (dev)  local  files  

Vlad  (dev)  local  files  

Ravikumar  (QA)  local  files  

Page 3: Princeton jug git_github

Centralized  file  repositories  

•  SVN  •  CVS  •  TFS  •  Perforce  •  …  

www.faratasystems.com  

Remote  Server  a.k.a.  repository  a.k.a.  repo    

Mary  (dev)  local  files  

Vlad  (dev)  local  files  

Ravikumar  (QA)  local  files  

Mary  commits  her  code  changes  to  the  remote  server  and  checks  out  Vlad’s  changes    Vlad  commits  his  code  changes  to  the  remote  server  and  checks  out  Mary’s  changes    Ravikumar  only  checks  out  the  code  for  the  QA  tesOng.      

Page 4: Princeton jug git_github

Distributed  file  repositories  

•  GIT  •  Mercurial  •  Bazaar  

www.faratasystems.com  

Remote  Repo  

Mary  (dev),  local  files,  local  repo  

Vlad  (dev),  local  files,  local  repo  

Ravikumar  (QA),  local  repo  

Each  developer  has  a  full  local  copy  of  the  repo.    It’s  hard  to  lose  the  repository  –  it’s  on  every  user’s  computer.    Each  user  always  works  with  the  local  repo  unOl  he  needs  to  synchronize.  

Page 5: Princeton jug git_github

Working  with  GIT  

www.faratasystems.com  

Remote  Git  Repo,  like  GitHub    

Mary  (dev),  local  files,  local  repo  

Vlad  (dev),  local  files,  local  repo  

Ravikumar  (QA),  local  repo  

Mary  works  on  the  plane  and  commits  her  code  changes  to  the  local  repo    Vlad  commits  his  code  changes  to  the  local  repo  and  pushes  latest  changes  to  the  remote  repo)    Ravikumar  works  for  QA.  He  pulls  out  the  code  for  tesOng.    

pull/push  

pull  

•  `  

Page 6: Princeton jug git_github

Sync  up  with  the  remote  server  

www.faratasystems.com  

Remote  Git    repository    

Mary  landed.  She  goes  to  Starbucks  to  get  online  to  pull  Vlad’s  changes  to  her  local  repo  and  push  hers  changes  to  the  remote  one.    

pull  

push  

Page 7: Princeton jug git_github

git  add  

www.faratasystems.com  

git  reset  

Staging  Area  

Page 8: Princeton jug git_github

git  commit  

www.faratasystems.com  

git  reset  –hard  HEAD~1  

Paying  for  groceries  Is  a  commitment.  But  sOll,    you  have  a  chance  to  return  them    

Page 9: Princeton jug git_github

git  push  

www.faratasystems.com  

Page 10: Princeton jug git_github

git  pull  

www.faratasystems.com  

Pulls  are  usually  done  from  a    remote  repository,  which  could  be  a  central  server  or  another  user’s  refrigerator  computer.    

Page 11: Princeton jug git_github

Downloads  and  documentaOon  •  hYp://git-­‐scm.com                                Git    

•  hYps://help.github.com              GitHub  repo  

•  hYp://git-­‐scm.com/book            Pro  Git  book  in  English  

•  hYp://git-­‐scm.com/book/ru  Pro  Git  book  in  Russian    •  hYp://gitref.org                                              Reference  manual  

www.faratasystems.com  

MAC  users,  if  you  already  had  an  older  version  of  git  installed,  a\er  installing  the  new  version    add  this  to  ~/.bash_profile:    export  PATH=/usr/local/git/bin:$PATH  

Page 12: Princeton jug git_github

Seang  up  name  and  email  

•  git  config  -­‐-­‐global  user.name  ”Yakov  Fain"      

•  git  config  -­‐-­‐global  user.email  "[email protected]"  

www.faratasystems.com  

Page 13: Princeton jug git_github

Two  Ways  of  CreaOng  a  New  Git  Repo  

1.   From  scratch            a)  cd  to  a  directory  where  your  project  files  are          b)  run  git  init  (this  will  create  .git  subdirectory)    

2.   Clone  the  exisOng  repo  from  somewhere,  e.g.  from  GitHub,  for  example:    git  clone  git://github.com/yfain/javatraining.git  

 

www.faratasystems.com  

You  can  start  version-­‐controlling  any  directory  at  any  Ome.  Just  go  into  this  dir  from  the    command  line  and  run  git  init  there.    

Page 14: Princeton jug git_github

Walkthrough  1:  git  init    

www.faratasystems.com  

1.  Go  to  a  Terminal  window    

2.  Create  an  empty  dir  temp1:  mkdir  temp1    

3.  cd  temp1    

4.  Directory  is  empty  ls  –la    

5.  Create  a  local  git  repo  git  init    

6.  Note  a  new  subdir  .git  ls  –la    

7.  See  the  structure  of  the  new  repo    tree  –a    

 There  is  no  logs  directory  yet.  The  objects  directrory  is  empty.        This  is  your  enOre  new  Git  repo.          

If  tree  command  doesn’t  work,  watch  this:  hYp://bit.ly/1bX2HqH      

Page 15: Princeton jug git_github

www.faratasystems.com  

You  can  start  version-­‐controlling  any  directory  at  any  Ome.      Just  go  into  this  directory  from  the  command  line  and  run  git  init  there.    

Page 16: Princeton jug git_github

CreaOng  a  file  and  commiang  to  a  repo  

www.faratasystems.com  

1.  Create  index.html:  <html>" <body bgcolor="red”>" </body>"</html>"  2.  Open  it  in  your  browser  –  it’s  red          3.  git  status  4.  git  add  .  5.  git  commit  –m  “created  red  page”    6.  Go  to  your  .git  directory.              a)  You’ll  see  new  log  subdir            b)  Look  inside  your  objects  dir  

Page 17: Princeton jug git_github

Branching    •  The  default  branch  is  master  

git  branch    •  To  create  a  branch  named  blue  

git  branch  blue  •  To  create  and  switch  to  branch  blue:  

 git  checkout  –b  blue    

•  To  switch  back  to  master:  git  checkout    master    

•  To  merge  blue  into  master:          git  merge  blue  

www.faratasystems.com  

Page 18: Princeton jug git_github

Walkthrough  2:  Adding  Another  Branch  

www.faratasystems.com  

1.  Check  which  branch  are  you  in  (should  be  in  master)                git  branch    2.  Create  a  new  branch  named  blue  and  switch  to  it:                git  checkout  –b  blue    3.  Change  the  background  in  index.html  to  be  blue:   <body bgcolor=”blue">"  Open  index.html  in  the  browser  –  background  should  be  blue "4.  Commit  the  change          git  add  .          git  commit  –m  “changing  background  from  red  to  blue”    5.  Switch  back  to  the  branch  master          git  checkout  master    6.  Open  index.html  in  your  browser  –  background  should  be  red.    Check  your  working  directory  –  there  is  only  one  version  of  index.html.  

Page 19: Princeton jug git_github

Walkthrough  3:  One  more  branch  +  merging  

www.faratasystems.com  

1.  Create  and  switch  one  more  branch  called  branch2  git  checkout  –b  branch2    

2.  Add  some  text  inside  the  <body>  tag  in  index.html:  <h1>Hello  from  branch2</h1>    Open  index.html  in  the  Web  browser    

3.  Commit  the  change:  git  add  .  git  commit  –m  “added  some  text  to  the  page”    

4.  Switch  back  to  master  branch  git  checkout  master    Open  index.html  –  it’s  red  and  no  text    

5.  Merge  with  branch2  git  merge  branch2  Open  index.html  –  it’s  red  with  text  

Page 20: Princeton jug git_github

Walkthrough  3:  Merge  conflict  

www.faratasystems.com  

Merging  master  with  blue  will  cause  the  conflict.    Master  branch  has    <body  bgcolor="red">  Blue  branch  has    <body  bgcolor=”blue”>      Open  index.html  in  the  editor  and  manually  change  it  to  keep  the  line  with  blue  color.      The  final  version  of  index.html:    <html>      <body  bgcolor="blue">              <h1>Hello  from  branch2</h1>      </body>  </html>      Do  git  add  .  and  git  commit      

Page 21: Princeton jug git_github

Global  Git  Config:      ~/.gitconfig  

 Local  Git  Config:  

 your_project_dir/.git/config  

www.faratasystems.com  

Git  config  files  

Page 22: Princeton jug git_github

GitHub:    HosOng  for  Git  

www.faratasystems.com  

Note:  Bitbucket.org  is  another  hosOng  service  for  Git  repositories.    Pricing:  hYps://bitbucket.org/account/user/yfain/plans/    

Page 23: Princeton jug git_github

GitHub  –  Online  Project  HosOng  For  Git  

To  start  using  GitHub  create  an  account  there.      You  can  create  an  organizaOon  and  add  users  to  the  organizaOon.    

www.faratasystems.com  

Page 24: Princeton jug git_github

Create  New  Repository  on  GitHub    

1.  Login  to  your  Github  account  2.  Select  the  tab  Repositories  and  create  new  

Repository    3.  Enter  the  name  of  the  project  and  its  

descripOon.  

www.faratasystems.com  

Page 25: Princeton jug git_github

Publishing  Your  Local  Project  to  GitHub  A\er  the  repository  is  created  you’ll  see  commands  to  run  from  your  desktop.  Say,  you  named  the  repo  temp1:  

www.faratasystems.com  

Open  command  or  Terminal  window,  switch  to  temp1  and  enter  the  above  commands.  

For  more  details  read  this:  hYps://help.github.com/arOcles/create-­‐a-­‐repo    

Page 26: Princeton jug git_github

Downloading  ExisOng  Repo  from  GitHub  

www.faratasystems.com  

Either  click  on  the  buYon  Clone  in  Desktop      or      download  the  repo  as  zip.    

To  clone  from  a  command  line  you  need  to  know  the  URL  of  the  repo,  for  example:      git  clone  git://github.com/johnsmith/mygreatprograms.git    or    git  clone  hYps://github.com/johnsmith/mygreatprograms  

Page 27: Princeton jug git_github

What’s  Pull  Request  

•  The  user  Viktor,  who  doesn’t  belong  to  our  project  can  fork  the  proj,  make  the  changes  and  send  a  Pull  Request.    

•  If  Yakov  agrees  to  the  pull  request  he  pulls  the  change  from  Viktor’s  repo  to  ours  –  he  goes  to  Pull  Requests  and  selects  Merge  Pull  Request.  

www.faratasystems.com  

Page 28: Princeton jug git_github

GitHub  Fork  

www.faratasystems.com  

Yakov’s  Github  Repo  

Viktor’s  Github  Repo  

Yakov’s  Desktop  

Viktor’s  Desktop  

Fork  

Pull  Request  

pull,  push  pull,  push  

pull,  push  

Page 29: Princeton jug git_github

Merging  Pull  Request  Sample  1  

www.faratasystems.com  

Page 30: Princeton jug git_github

Merging  Pull  Request  Sample  2  

www.faratasystems.com  

Page 31: Princeton jug git_github

Contact  Info  

•  [email protected]  •  [email protected]    

•  @yfain    •  @gAmUssA  

www.faratasystems.com