Git for dummies

What is Git?

Git is a version control system (CVS) designed to make our life much, much easier.
By saving revisions (commits), Git allows us to browse through history and change, modify, go back or cherry pick specific files.

You can finally change history!

Installation (Windows)
http://code.google.com/p/msysgit/downloads/list → Full installer for official Git for Windows

Git bash
cd c:/Program Files/
git clone –recursive git://github.com/nvie/gitflow.git

Windows files explorer
browse to c:/Program Files/Git/bin/
http://ww.codeoasis.com/Downloads/git/gitflow-dependencies.zip → download and extract

Windows CLI
windows+r → cmd (open windows command line)
dir c:/Program Files/gitflow
contrib\msygit-install.cmd “c:/program files/git/”

Basic workflow
clone a project
cd /var/www
git clone ssh://@lxst.codeoasis.com/var/git/
cd
git branch –track dev origin/dev → track the development branch locally.
git flow init → Press Enter for all
git checkout dev → basically we work only on develop and feature branch

working around
git flow feature start → create and work on a feature
— work work work. — git add [files to commit]
git commit → prompts for a message. please describe.
— commit commit commit. — git flow feature finish → finish him! fatality!

sharing with others
git pull → get all recent updates.
git push → share your code with others.

Git – the features

  • Local – does nearly all of it’s operations without needing a network connection
  • Very fast – due to the fact that none of Git’s operations has any dependency on network latency
  • Fully distributed – you can collaborate with different groups of people in different ways simultaneously within the same project.
  • Non-linear – support of working on multiple parallel lines
  • Efficient – Able to handle large projects like the Linux kernel
  • Snapshots, not differences – Git doesn’t store the file again – just a link to the previous identical file it has already stored.
  • Has integrity – You can’t lose information in transit or get file corruption without Git being able to detect it.
  • Generally only adds data – very difficult to get the system to do anything that is not undoable or to make it erase data in any way.
    Git – definitions
    commit – creating a record of a snapshot.
    snapshot – manifest of what the file(s) in your project look like at a certain point in time.
    branch – a light-weight and portable pointer to a commit object.
    HEAD – special pointer that allows Git to recognize what branch is currently checked-out.

    //Git file states:
    un-tracked – a file that Git recognizes in the repository but doesn’t track.
    tracked – files that Git tracks for changes and modifications.
    modified – tracked file has been changed but wasn’t committed to the database
    staged – modified file in its current version marked to go into the next commit snapshot
    commited – file whose data is safely stored in the local database.

    basic commands
    //workflow commands
    Git status //check the status
    Git diff //Git diff shows changes that are still unchanged
    Git log //check the commits history
    Git checkout [branchName] //move to a specific branch
    Git branch -d [branchName] //delete a specific branch

    //handling files
    Git add [file] //staging files (new and modified)
    Git commit //commit the staged changes
    Git rm [file] //remove files
    Git mv [file] //moves/renames and file

    //remote commands
    Git fetch //pulls down all the data from that remote project that you don’t have
    Git pull //fetch from a remote repo and try to merge into the current branch
    Git push //push your new data and branches to remote repository

    Git work flow
    origin repository – central “truth” repository. only considered to be the central one.

    //main branches
    master branch – main branch that reflects a production-ready state.
    develop branch – branch that reflects a state with the latest delivered development changes for the next release.

    //support branches
    feature branch – used to develop new features for the upcoming or a distant future release.
    feature – a small set of code that completes a sub-section of a business case.
    release branch – support preparation of a new production release, for last minute dotting of i’s and crossing t’s.
    hotfix branch– prepare for a new production release, albeit unplanned.

    Git flow commands
    //starting to work
    new project:
    Git flow init
    Git push –set-upstream origin develop
    Git push –set-upstream origin master

    cloned project:
    Git branch –track develop origin/develop
    Git branch –track master origin/master
    Git flow init

    //feature branches
    Git flow feature start [featureName]
    Git flow feature finish [featureName]
    Git flow feature publish [featureName]
    Git flow feature pull [alias] [featureName]

    //release branches
    Git flow release start [releaseName]
    Git flow release finish [releaseName]
    Git flow release publish [releaseName]
    Git flow release pull [releaseName]

    //hotfix branches
    Git flow hotfix start [hotfixName]
    Git flow hotfix finish [hotfixName]

    Sources:

    http://nvie.com/posts/a-successful-git-branching-model/
    http://git-scm.com/book

    By Elad Rome