Subversion and Git




CS174

Chris Pollett

Oct. 2, 2013

Outline

Subversion

Setting up your Repository

Trunk, Branches, Tags

Basic Work Cycle

More Basic Work Cycle

Add, Delete, Diff

Issue Tracking

svn copy, merge

Git

  • When we introduced version control systems we said we were going to consider one system based on the central repository model (Subversion) and one distributed system (Git).
  • Git has been around since 2005, and was originally developed by Linus Torvald, the creator of Linux.
  • Git has a nice website for publically hosting git repositories known as GitHub. Repositories on this sites get their own issue tracker (with rss feed) and wiki.
  • Git uses many commands in a similar way to svn; however, there are some key differences which we will see as we go along.
  • To begin to set up a git repository move to where you would like to have your repository and type:
    git init name_of_git_repository.
    
  • If you cd into this directory and do an ls -a to see hidden files, you will see a .git folder.
  • This is where git keeps track of stuff, unlike svn, each subfolder of your repository doesn't get a .git folder -- svn allows you to check out sub-folders of a repository, with git you essentially always check out a whole everything in a whole branch.
  • If you want to let someone to get a copy of your repository, you copy the repository folder on to a usb key (a key without Stuxnet please), give it to the person you want to have the repository.
  • The person that wants to get your repository, might have an existing repository that they want to get your stuff into or might be starting from scratch. They issue a commands like:
    git clone path_to_clone_from to_folder #from scratch case
    git pull path_to_from_repos branch_name_you_want_to_pull_into #existing case
    git checkout branch #makes branch the current branch in the repository you are working on
    
  • Notice sharing can be done locally without the need for a central repository, you can zip your git folders and e-mail, git even has its own e-mail commands.
  • To see information about git commands, you can type 'git help', or 'git command --help'
  • Example Creating a Repository

  • Here is a short example of creating a repository on a *nix system in the directory /Users/cpollett
    mkdir myrepos
    cd myrepos
    git init
    git add .
    echo "hi there" > test.txt
    git add test.txt
    git commit -a -m "Initial commit"
    cd ..
    git clone file:///Users/cpollett/myrepos myrepos2
    cd myrepos2 # now start editing myrepos2
    echo "test2" > test2.txt
    git add test2.txt
    git commit -a -m "Made some changes"
    cd ../myrepos #now want to get changes back in myrepos
    git pull file:///Users/cpollett/myrepos2 master
    
    This produces a copy of the repository in a separate folder. We then edit the copy, and pull the changes back (the changes were in the clone's master branch) into the original repository. We will describe git add and git commit in a moment.
  • If in myrepos2 we had want to get changes from myrepos, we could simply have done:
    git pull
    
    as git will default to pulling where it was cloned from.
  • Creating a WebDav repository

    Configuring your Repository

    Adding, Moving Files

    Committing changes

    Branches, Merging Branches

    Example resolving conflicts

    Making patches

    Git Tags