SlideShare a Scribd company logo
From SVN to Git
                   with a pinch of GitHub




Marco De Stefano
                                            "
SVN features


  Centralized version control

  Commit as atomic operation

  Versioning mantained for directories and le metadata

  Client/Server protocol sends diffs

✘  Renaming of les causes loss of the history

✘  .svn directories in the whole project

✘  Lack of management tools (e.g. deleting part of the history)
SVN commands

  >svn checkout (co)

  >svn commit (ci)

  >svn status (st)

  >svn update

  >svn revert

  >svn add/rm

  >svnadmin create

  …
Centralized vs. Distributed version control


  “Centralized VCS systems are designed with the intent that there is One
   True Source that is Blessed, and therefore Good. All developers work
   (checkout) from that source, and then add (commit) their changes, which
   then become similarly Blessed.”

  “Distributed VCS systems are designed with the intent that one repository
   is as good as any other, and that merges from one repository to another
   are just another form of communication. Any semantic value as to which
   repository should be trusted is imposed from the outside by process, not
   by the software itself.”

  “The real choice between using one type or the other is organizational - if
   your project or organization wants centralized control, then a DVCS is a
   non-starter. If your developers are expected to work all over the country/
   world, without secure broadband connections to a central repository, then
   DVCS is probably your salvation. If you need both, you're fu***d.”
Centralized vs. Distributed version control
Centralized vs. Distributed version control
Git features


  Distributed version control

  Strong support for non-linear development (branches and merges)

  Efficient handling of large projects (e.g. Linux Kernel)

  Pluggable merge strategies

  .git directory in project root

✘  More disk space required

✘  Not for Windows  (but there is a native porting, msysgit)
Git commands

  >git init
  Creates a .git subdirectory in your project

  Your working directory becomes a git repository




You use git init to make an existing directory of content into a new Git repository.
You can do this in any directory at any time, completely locally
Git commands

  >git clone <url> [path]
  Copies a project in your working directory

  It copies all the project history locally

  You will get a directory with the main branch of the project




You use git clone to get a local copy of a Git repository
Git commands

  >git add [ lepattern…]
  Adds le contents to your staging area

  Used for new les and modi cations to existing les

  Possible to skip this operation (with commit –a option)




You use git add to start tracking les and to stage changes to already tracked les
i.e. whenever you want to include le changes in the next commit
Git commands

  >git status [-s]
  Shows the status of the les (working directory and staging area)

  Gives context and hints – displays which (but not how) les changed

  -s option gives short output (with no hints – similar to svn st)




You use git status to see if anything has been modi ed and/or staged since the
last commit
Git commands

  >git diff [--cached / HEAD] [--stat] [ lepath]
  Shows a patch of content changed since last commit and not yet staged

  --cached option shows the staged changes, HEAD shows both staged and
   unstaged changes

  --stat option gives short output


You use git diff to see how (line by line) les have been modi ed and/or staged
since the last commit
Git commands


  >git commit [-a] [-m ‘commit message’]
  Records a snapshot of the staging area in the current branch

  -a option adds to the snapshot all the unstaged changes

  -m option allows to insert the commit message directly



You use git commit to record a snapshot of the staged changes. This snapshot can
then be compared, shared and reverted to, if you need to
Git commands

  >git reset [--hard] <HEAD/commit> [-- les…]
  Unstages changes that have been staged

  With --hard options, the repository changes to the last commit state

  Possible to unstage single les



You use git reset HEAD to unstage les previously staged with git add, to avoid
including them in the next commit
Git commands


  >git rm [--cached] [ les…]
  Removes les from the staging area – and from the working directory

  --cached option allows to retain the le in the working directory




You use git rm to remove les from being tracked in Git
Git commands


  >git mv <source> <destination>
  Has the same behaviour of:
         >git rm --cached <source>
         >mv <source> <destination>
         >git add <destination>




You use git mv to rename les under version control
Git commands

  >git branch [-d <branchname>] [branchname]
  A branch is a context where you can switch

  Without arguments, it lists out the local branches and points out the current
   one

  With a branch name, it creates a new branch – the default one is named master

  -d option will delete branchname


You use git branch to list current branches, create new branches and delete
unnecessary branches
Git commands

  >git checkout [[-b] <branchname>]/ [-- les…]
  Swithces to branchname

  -b option will create branchname and switch immediately to it

  -- followed by one or more les, reverts the content of these les to the
   last commit state



You use git checkout to switch among branches, optionally creating them; you
also use it to revert the data of any le to the last commit
Git commands


 >git merge <branchname>
  Merges the diffs between the current branch and branchname into the
  current one

  The branch branchname doesn’t change




You use git merge to combine another branch context into the current one
Git commands

  >git log [--oneline] [--graph] [--decorate] [branchname]
  Shows commit history of branchname (the current one if not speci ed)

  The --oneline options shows only the rst row of the commit message

  The --graph option shows a graph of branches and merges

  The --decorate option shows information on branches involved in merges


You use git log to list out the commit history
Git commands

  >git remote [-v] [add <url> <alias>]/[rm <alias>]
  Lists the remote repository aliases stored, -v options also shows the urls

  Possible to have different push and fetch urls

  add allows to add the repository at url under the local-remote alias

  rm allows to remove the alias local-remote


You use git remote to list out the remote repositories and the urls they’re using.
You can also add and remove local-remote repositories
Git commands


  >git fetch <alias/--all>
  Downloads branches and data from a remote repository

  --all option allows to download data from all remote repositories

  Cannot checkout a remote repository




You use git fetch to synchronize your repository with a remote repository,
fetching all the data not already existing in your local repository
Git commands


 >git pull <alias>/<--all>
  Fetches from a remote repository and tries to merge it into the current branch

  Has the same behaviour of:
       >git fetch <alias>
       >git merge <alias>



You use git pull to synchronize your repository with a remote repository, fetching
all the data not already existing in your local repository and merging it into the
current branch
Git commands


 >git push <alias> [branch]
  Pushes local branches and data to a remote repository

  If no branch is speci ed, the current branch is used

  The local branch to push has to be up-to-date



You use git push to update a remote repository with changes made locally
Git commands


 >git revert [-n] <HEAD/commit>
  Reverts the contents of the current branch to the commit state

  It makes a new commit on the current branch!

  With -n options the data is reverted and isn’t committed



You use git revert to revert the data in the current branch to a speci ed state
Git commands


 >git stash <save/pop>
  Allows to record the current state of the working directory

  Doesn’t make a commit

  Save allows to create a stash, pop puts the stashed changes back on the
   working directory

You use git stash to temporarily stash (and afterwords recover) the data in the
current branch, e.g to proceed with a pull request
Tips

  Enable console colors
     >git con g --global color.diff auto
     >git con g --global color.status auto
     >git con g --global color.branch auto

  Set name and email
     >git con g --global user.name <Name and Surname>
     >git con g --global user.email <email>

  Set aliases for commands, e.g.:
     >git con g --global alias.history ‘log --oneline --graph --decorate’
     >git con g --global alias.st ‘status -s’
     >git con g --global alias.ci ‘commit -m’
     >git con g --global alias.co checkout
GitHub




  Web-based hosting service for software
  development projects that use Git
  Possible to have public repositories (free if they
  require less than 300MB)
GitHub – Create a repo
GitHub – Create a repo

  >mkdir help-example
  >cd help-example
  >git init
  >touch README
  >git commit -a –m ‘ rst commit’
  >git remote add origin git@github.com:tekkub/help-
  example.git
  >git push origin master
GitHub – Push data

  I can’t push, “Permission denied (public key)”
  To push data, you have to set up a pair of SSH keys,
  and add your public key in the account options on
  GitHub
  You can also con gure your GitHub account locally:
     >git con g --global github.user <username>
     >git con g --global github.token <token>

  You can nd your token under your GitHub account
  settings
A simple scenario

  Alice created her repo, test, on github (see previous
  slides), containing these les:
    README foo.txt bar.txt test.c	

  Bob joins her – and he has write access to the
  repository:
    >git clone git@github.com/alice/test.git test	

  Bob works locally, and makes a branch:
    >cd test	
    >git checkout –b text-changes	

  Now he has 2 branches: master and text-changes
A simple scenario

  Bob modi es foo.txt and bar.txt; after that he runs:
    >git add foo.txt	
    >git status –s	
       M bar.txt	
        M foo.txt	

  The le bar.txt has been modi ed but not already
  staged; however Bob runs:
    >git commit –a –m ‘modified txt files’	
    >git status –s   gives no output
  These les have been modi ed only in text-changes
  branch
A simple scenario


  Bob wants to modify test.c in a new branch, without
  having the *.txt les modi ed
    >git checkout master	
    >git branch src-changes	
    >git checkout src-changes	

  Bob modi es the le test.c and after that he runs:
    >git add .	
    >git commit –m ‘modified test file’	

  Bob has 3 branches: master, text-changes, src-changes
A simple scenario


  Meanwhile, Alice modi es README and test.c, and
  runs:
    >git commit –a –m ‘modified readme and test.c’	
    >git push origin	

  Bob tries to merge text-changes with src-changes
    >git branch	
          master	
        * src-changes	
          text-changes	
    >git merge text-changes
A simple scenario


  Bob tries to push the changes into the origin
    >git checkout master	
    >git merge src-changes	
    >git push origin	

  However, Bob can’t push data to the origin, because he
  is not up-to-date
    >git pull	

  What happens with the le test.c? Both Alice and Bob
  modi ed it
A simple scenario


  Git tries to merge contents – and it’s very likely to be able
  to do it

  If Git can’t merge correctly, Bob will see the classic merging
  style on his copy of test.c:
      <<<<<<<<< yours: test.c	
      //Bob’s content	
      =========	
      //Alice’s content	
      >>>>>>>>> theirs: test.c	


  After merging, Bob can push his data to the origin
    >git push origin
What else?

  Git Reference

  Git Tutorial

  Git User’s Manual

  Pro Git Book

  Git Community Book

  GitHub Help

  Egit - Eclipse plugin

  Graphical frontend:
     Windows, Linux (gtk), Mac OSX, Multi-platform

More Related Content

What's hot (20)

PPT
The Kotlin Programming Language
intelliyole
 
PPTX
Android Services
Ahsanul Karim
 
PPTX
TestNG Framework
Levon Apreyan
 
PDF
Manipulating Android tasks and back stack
Ran Nachmany
 
PPT
Object Oriented Programming with Java
backdoor
 
PPT
Android | Android Activity Launch Modes and Tasks | Gonçalo Silva
JAX London
 
PDF
Hacking Jenkins
Miro Cupak
 
PDF
Case study: Open Source Automation Framework using Selenium WebDriver
RTTS
 
PPTX
C# Generics
Rohit Vipin Mathews
 
PDF
Analysing in depth work manager
bhatnagar.gaurav83
 
PPTX
Introduction to Koltin for Android Part I
Atif AbbAsi
 
PPT
android activity
Deepa Rani
 
PPTX
C# Constructors
Prem Kumar Badri
 
PDF
Java 8 Lambda Built-in Functional Interfaces
Ganesh Samarthyam
 
PPTX
Exception Handling in C#
Abid Kohistani
 
PPT
Inheritance C#
Raghuveer Guthikonda
 
PDF
Core java complete notes - Contact at +91-814-614-5674
Lokesh Kakkar Mobile No. 814-614-5674
 
PPTX
Api testing
Keshav Kashyap
 
PPTX
[OOP - Lec 08] Encapsulation (Information Hiding)
Muhammad Hammad Waseem
 
PPTX
Types of inheritance in java
chauhankapil
 
The Kotlin Programming Language
intelliyole
 
Android Services
Ahsanul Karim
 
TestNG Framework
Levon Apreyan
 
Manipulating Android tasks and back stack
Ran Nachmany
 
Object Oriented Programming with Java
backdoor
 
Android | Android Activity Launch Modes and Tasks | Gonçalo Silva
JAX London
 
Hacking Jenkins
Miro Cupak
 
Case study: Open Source Automation Framework using Selenium WebDriver
RTTS
 
C# Generics
Rohit Vipin Mathews
 
Analysing in depth work manager
bhatnagar.gaurav83
 
Introduction to Koltin for Android Part I
Atif AbbAsi
 
android activity
Deepa Rani
 
C# Constructors
Prem Kumar Badri
 
Java 8 Lambda Built-in Functional Interfaces
Ganesh Samarthyam
 
Exception Handling in C#
Abid Kohistani
 
Inheritance C#
Raghuveer Guthikonda
 
Core java complete notes - Contact at +91-814-614-5674
Lokesh Kakkar Mobile No. 814-614-5674
 
Api testing
Keshav Kashyap
 
[OOP - Lec 08] Encapsulation (Information Hiding)
Muhammad Hammad Waseem
 
Types of inheritance in java
chauhankapil
 

Viewers also liked (20)

ODP
Git vs svn
Suman Mukherjee
 
PPT
Git vs SVN
neuros
 
PDF
GIT / SVN
Torben Brodt
 
PPTX
01 - Git vs SVN
Edward Goikhman
 
PPTX
From svn to git
Nehal Shah
 
PPTX
Git vs svn
Rupesh Kumar
 
PDF
Comparison of SVN and Git
Daniel Wieth
 
PDF
Git: A Getting Started Presentation
Nap Ramirez
 
PDF
Découvrir et utiliser Git : le logiciel de gestion de versions décentralisé
ECAM Brussels Engineering School
 
PDF
From SVN to Git
Sergio Gutierrez-Santos
 
PDF
Git Flow: un processus de développement Agile
Xavier Hausherr
 
ODP
Svn Basic Tutorial
Marco Pivetta
 
PDF
Git 101: Git and GitHub for Beginners
HubSpot
 
PDF
Quick Introduction to git
Joel Krebs
 
PPTX
En quoi git serait plus agile que svn ?
Guillaume Collic
 
PDF
Getting Started on distributed version control with git
Anoop Thomas Mathew
 
PDF
Git Tutorial I
Jim Yeh
 
PDF
Apache contribution-bar camp-colombo
Sagara Gunathunga
 
PDF
Getting your open source company to contribution
Asavin Wattanajantra
 
PDF
Getting started with git svn
Manij Shrestha
 
Git vs svn
Suman Mukherjee
 
Git vs SVN
neuros
 
GIT / SVN
Torben Brodt
 
01 - Git vs SVN
Edward Goikhman
 
From svn to git
Nehal Shah
 
Git vs svn
Rupesh Kumar
 
Comparison of SVN and Git
Daniel Wieth
 
Git: A Getting Started Presentation
Nap Ramirez
 
Découvrir et utiliser Git : le logiciel de gestion de versions décentralisé
ECAM Brussels Engineering School
 
From SVN to Git
Sergio Gutierrez-Santos
 
Git Flow: un processus de développement Agile
Xavier Hausherr
 
Svn Basic Tutorial
Marco Pivetta
 
Git 101: Git and GitHub for Beginners
HubSpot
 
Quick Introduction to git
Joel Krebs
 
En quoi git serait plus agile que svn ?
Guillaume Collic
 
Getting Started on distributed version control with git
Anoop Thomas Mathew
 
Git Tutorial I
Jim Yeh
 
Apache contribution-bar camp-colombo
Sagara Gunathunga
 
Getting your open source company to contribution
Asavin Wattanajantra
 
Getting started with git svn
Manij Shrestha
 
Ad

Similar to SVN 2 Git (20)

PPTX
Getting Started with Git: A Primer for SVN and TFS Users
Noam Kfir
 
PDF
Git training
eric7master
 
PPT
Git presentation
James Cuzella
 
PPTX
Git and GitHub
Priya Nayak
 
PPTX
Learning Basic GIT Cmd
srinathcox
 
PPTX
Introduction to Git and Github
Max Claus Nunes
 
KEY
Git Tech Talk
Chris Johnson
 
PPTX
Git learning
Amit Gupta
 
PDF
git.ppt.pdf
Roniel Lopez Alvarez
 
PPTX
Git basic
Akbar Uddin
 
PPTX
An introduction to Git
Muhil Vannan
 
PPTX
GIT.pptx
Soumen Debgupta
 
DOCX
Git commands
Javed Hussain
 
PDF
Git training v10
Skander Hamza
 
PDF
Git
Maks Charuk
 
PPTX
Getting Git...before it gets you
Jeremy Brown
 
PPTX
GIT Training
Muhammad Ibrar
 
PDF
Advanced Git Tutorial
Sage Sharp
 
PPTX
sample.pptx
UshaSuray
 
Getting Started with Git: A Primer for SVN and TFS Users
Noam Kfir
 
Git training
eric7master
 
Git presentation
James Cuzella
 
Git and GitHub
Priya Nayak
 
Learning Basic GIT Cmd
srinathcox
 
Introduction to Git and Github
Max Claus Nunes
 
Git Tech Talk
Chris Johnson
 
Git learning
Amit Gupta
 
Git basic
Akbar Uddin
 
An introduction to Git
Muhil Vannan
 
GIT.pptx
Soumen Debgupta
 
Git commands
Javed Hussain
 
Git training v10
Skander Hamza
 
Getting Git...before it gets you
Jeremy Brown
 
GIT Training
Muhammad Ibrar
 
Advanced Git Tutorial
Sage Sharp
 
sample.pptx
UshaSuray
 
Ad

Recently uploaded (20)

PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PDF
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 

SVN 2 Git

  • 1. From SVN to Git with a pinch of GitHub Marco De Stefano "
  • 2. SVN features   Centralized version control   Commit as atomic operation   Versioning mantained for directories and le metadata   Client/Server protocol sends diffs ✘  Renaming of les causes loss of the history ✘  .svn directories in the whole project ✘  Lack of management tools (e.g. deleting part of the history)
  • 3. SVN commands   >svn checkout (co)   >svn commit (ci)   >svn status (st)   >svn update   >svn revert   >svn add/rm   >svnadmin create   …
  • 4. Centralized vs. Distributed version control   “Centralized VCS systems are designed with the intent that there is One True Source that is Blessed, and therefore Good. All developers work (checkout) from that source, and then add (commit) their changes, which then become similarly Blessed.”   “Distributed VCS systems are designed with the intent that one repository is as good as any other, and that merges from one repository to another are just another form of communication. Any semantic value as to which repository should be trusted is imposed from the outside by process, not by the software itself.”   “The real choice between using one type or the other is organizational - if your project or organization wants centralized control, then a DVCS is a non-starter. If your developers are expected to work all over the country/ world, without secure broadband connections to a central repository, then DVCS is probably your salvation. If you need both, you're fu***d.”
  • 5. Centralized vs. Distributed version control
  • 6. Centralized vs. Distributed version control
  • 7. Git features   Distributed version control   Strong support for non-linear development (branches and merges)   Efficient handling of large projects (e.g. Linux Kernel)   Pluggable merge strategies   .git directory in project root ✘  More disk space required ✘  Not for Windows  (but there is a native porting, msysgit)
  • 8. Git commands   >git init   Creates a .git subdirectory in your project   Your working directory becomes a git repository You use git init to make an existing directory of content into a new Git repository. You can do this in any directory at any time, completely locally
  • 9. Git commands   >git clone <url> [path]   Copies a project in your working directory   It copies all the project history locally   You will get a directory with the main branch of the project You use git clone to get a local copy of a Git repository
  • 10. Git commands   >git add [ lepattern…]   Adds le contents to your staging area   Used for new les and modi cations to existing les   Possible to skip this operation (with commit –a option) You use git add to start tracking les and to stage changes to already tracked les i.e. whenever you want to include le changes in the next commit
  • 11. Git commands   >git status [-s]   Shows the status of the les (working directory and staging area)   Gives context and hints – displays which (but not how) les changed   -s option gives short output (with no hints – similar to svn st) You use git status to see if anything has been modi ed and/or staged since the last commit
  • 12. Git commands   >git diff [--cached / HEAD] [--stat] [ lepath]   Shows a patch of content changed since last commit and not yet staged   --cached option shows the staged changes, HEAD shows both staged and unstaged changes   --stat option gives short output You use git diff to see how (line by line) les have been modi ed and/or staged since the last commit
  • 13. Git commands   >git commit [-a] [-m ‘commit message’]   Records a snapshot of the staging area in the current branch   -a option adds to the snapshot all the unstaged changes   -m option allows to insert the commit message directly You use git commit to record a snapshot of the staged changes. This snapshot can then be compared, shared and reverted to, if you need to
  • 14. Git commands   >git reset [--hard] <HEAD/commit> [-- les…]   Unstages changes that have been staged   With --hard options, the repository changes to the last commit state   Possible to unstage single les You use git reset HEAD to unstage les previously staged with git add, to avoid including them in the next commit
  • 15. Git commands   >git rm [--cached] [ les…]   Removes les from the staging area – and from the working directory   --cached option allows to retain the le in the working directory You use git rm to remove les from being tracked in Git
  • 16. Git commands   >git mv <source> <destination>   Has the same behaviour of:   >git rm --cached <source>   >mv <source> <destination>   >git add <destination> You use git mv to rename les under version control
  • 17. Git commands   >git branch [-d <branchname>] [branchname]   A branch is a context where you can switch   Without arguments, it lists out the local branches and points out the current one   With a branch name, it creates a new branch – the default one is named master   -d option will delete branchname You use git branch to list current branches, create new branches and delete unnecessary branches
  • 18. Git commands   >git checkout [[-b] <branchname>]/ [-- les…]   Swithces to branchname   -b option will create branchname and switch immediately to it   -- followed by one or more les, reverts the content of these les to the last commit state You use git checkout to switch among branches, optionally creating them; you also use it to revert the data of any le to the last commit
  • 19. Git commands  >git merge <branchname>   Merges the diffs between the current branch and branchname into the current one   The branch branchname doesn’t change You use git merge to combine another branch context into the current one
  • 20. Git commands   >git log [--oneline] [--graph] [--decorate] [branchname]   Shows commit history of branchname (the current one if not speci ed)   The --oneline options shows only the rst row of the commit message   The --graph option shows a graph of branches and merges   The --decorate option shows information on branches involved in merges You use git log to list out the commit history
  • 21. Git commands   >git remote [-v] [add <url> <alias>]/[rm <alias>]   Lists the remote repository aliases stored, -v options also shows the urls   Possible to have different push and fetch urls   add allows to add the repository at url under the local-remote alias   rm allows to remove the alias local-remote You use git remote to list out the remote repositories and the urls they’re using. You can also add and remove local-remote repositories
  • 22. Git commands   >git fetch <alias/--all>   Downloads branches and data from a remote repository   --all option allows to download data from all remote repositories   Cannot checkout a remote repository You use git fetch to synchronize your repository with a remote repository, fetching all the data not already existing in your local repository
  • 23. Git commands  >git pull <alias>/<--all>   Fetches from a remote repository and tries to merge it into the current branch   Has the same behaviour of:   >git fetch <alias>   >git merge <alias> You use git pull to synchronize your repository with a remote repository, fetching all the data not already existing in your local repository and merging it into the current branch
  • 24. Git commands  >git push <alias> [branch]   Pushes local branches and data to a remote repository   If no branch is speci ed, the current branch is used   The local branch to push has to be up-to-date You use git push to update a remote repository with changes made locally
  • 25. Git commands  >git revert [-n] <HEAD/commit>   Reverts the contents of the current branch to the commit state   It makes a new commit on the current branch!   With -n options the data is reverted and isn’t committed You use git revert to revert the data in the current branch to a speci ed state
  • 26. Git commands  >git stash <save/pop>   Allows to record the current state of the working directory   Doesn’t make a commit   Save allows to create a stash, pop puts the stashed changes back on the working directory You use git stash to temporarily stash (and afterwords recover) the data in the current branch, e.g to proceed with a pull request
  • 27. Tips   Enable console colors   >git con g --global color.diff auto   >git con g --global color.status auto   >git con g --global color.branch auto   Set name and email   >git con g --global user.name <Name and Surname>   >git con g --global user.email <email>   Set aliases for commands, e.g.:   >git con g --global alias.history ‘log --oneline --graph --decorate’   >git con g --global alias.st ‘status -s’   >git con g --global alias.ci ‘commit -m’   >git con g --global alias.co checkout
  • 28. GitHub   Web-based hosting service for software development projects that use Git   Possible to have public repositories (free if they require less than 300MB)
  • 30. GitHub – Create a repo   >mkdir help-example   >cd help-example   >git init   >touch README   >git commit -a –m ‘ rst commit’   >git remote add origin [email protected]:tekkub/help- example.git   >git push origin master
  • 31. GitHub – Push data   I can’t push, “Permission denied (public key)”   To push data, you have to set up a pair of SSH keys, and add your public key in the account options on GitHub   You can also con gure your GitHub account locally:   >git con g --global github.user <username>   >git con g --global github.token <token>   You can nd your token under your GitHub account settings
  • 32. A simple scenario   Alice created her repo, test, on github (see previous slides), containing these les:   README foo.txt bar.txt test.c   Bob joins her – and he has write access to the repository:   >git clone [email protected]/alice/test.git test   Bob works locally, and makes a branch:   >cd test   >git checkout –b text-changes   Now he has 2 branches: master and text-changes
  • 33. A simple scenario   Bob modi es foo.txt and bar.txt; after that he runs:   >git add foo.txt   >git status –s   M bar.txt   M foo.txt   The le bar.txt has been modi ed but not already staged; however Bob runs:   >git commit –a –m ‘modified txt files’   >git status –s gives no output   These les have been modi ed only in text-changes branch
  • 34. A simple scenario   Bob wants to modify test.c in a new branch, without having the *.txt les modi ed   >git checkout master   >git branch src-changes   >git checkout src-changes   Bob modi es the le test.c and after that he runs:   >git add .   >git commit –m ‘modified test file’   Bob has 3 branches: master, text-changes, src-changes
  • 35. A simple scenario   Meanwhile, Alice modi es README and test.c, and runs:   >git commit –a –m ‘modified readme and test.c’   >git push origin   Bob tries to merge text-changes with src-changes   >git branch   master   * src-changes   text-changes   >git merge text-changes
  • 36. A simple scenario   Bob tries to push the changes into the origin   >git checkout master   >git merge src-changes   >git push origin   However, Bob can’t push data to the origin, because he is not up-to-date   >git pull   What happens with the le test.c? Both Alice and Bob modi ed it
  • 37. A simple scenario   Git tries to merge contents – and it’s very likely to be able to do it   If Git can’t merge correctly, Bob will see the classic merging style on his copy of test.c:   <<<<<<<<< yours: test.c   //Bob’s content   =========   //Alice’s content   >>>>>>>>> theirs: test.c   After merging, Bob can push his data to the origin   >git push origin
  • 38. What else?   Git Reference   Git Tutorial   Git User’s Manual   Pro Git Book   Git Community Book   GitHub Help   Egit - Eclipse plugin   Graphical frontend:   Windows, Linux (gtk), Mac OSX, Multi-platform