CSC/ECE 517 Fall 2014/ch1a F1415 rv

From Expertiza_Wiki
Jump to navigation Jump to search

Introduction

What is Git?

Git (/ɡɪt/) is a locally enabled distributed revision control and source code management (SCM) system with an emphasis on speed, data integrity, and support for distributed, non-linear workflows. Git was initially designed and developed by Linus Torvalds for Linux kernel development in 2005, and has since become the most widely adopted version control system for software development. Github, a git repository web-based hosting service is in fact the largest code host on the planet with over 15.7 million repositories. Large or small, every repository comes with the same powerful tools. These tools are open to the community for public projects and secure for private projects. As with most other distributed revision control systems, and unlike most client–server systems, every Git working directory is a full-fledged repository with complete history and full version-tracking capabilities, independent of network access or a central server. Like the Linux kernel, Git is free software distributed under the terms of the GNU General Public License version 2.

Why Distributed Version Control System?

Distributed Revision Control Systems (DRCS) take a peer-to-peer approach, as opposed to the client-server approach of centralized systems. Rather than a single, central repository on which clients synchronize, each peer's working copy of the codebase is a bona-fide repository.Distributed revision control conducts synchronization by exchanging patches(change-sets) from peer to peer. This results in some important differences from a centralized system:

  • No canonical, reference copy of the codebase exists by default; only working copies.
  • Common operations (such as commits, viewing history, and reverting changes) are fast, because there is no need to communicate with a central server.
  • Rather, communication is only necessary when pushing or pulling changes to or from other peers.
  • Each working copy effectively functions as a remote backup of the codebase and of its change-history, providing inherent protection against data loss.

The act of cloning an entire repository gives distributed version control tools several advantages over centralized systems:

  • Performing actions other than pushing and pulling changesets is extremely fast because the tool only needs to access the hard drive, not a remote server.
  • Committing new changesets can be done locally without anyone else seeing them. Once you have a group of changesets ready, you can push all of them at once.
  • Everything but pushing and pulling can be done without an internet connection. So you can work on a plane, and you won’t be forced to commit several bugfixes as one big changeset.
  • Since each programmer has a full copy of the project repository, they can share changes with one or two other people at a time if they want to get some feedback before showing the changes to everyone.

Why Git?

Branching Model Git's most compelling feature that really makes it stand apart from nearly every other SCM out there is its branching model.Git will allow you to have multiple local branches that can be entirely independent of each other and the creation, merging and deletion of those lines of development take seconds. This means that you can do things like:

• Create experimental branches.
• Clear cut Branch delineation into production,Development,Testing,Fixes,Patches,etc.
• Seamless Navigation across feature branches and Code Versions.
• Create and Work on your own patches, features and tests without effecting the Production/Master branch.
• Independent Merging and Management of one's content changes.

Everything is Local There is very little outside of 'fetch', 'pull' and 'push' that communicates in any way with anything other than your hard disk.This not only makes most operations much faster than you may be used to, but it also allows you to work on stuff offline. That may not sound like a big deal, but I'm always amazed at how often I actually do work offline. Being able to branch, merge, commit and browse history of your project while on the plane or train is very productive. local repo to remote repo flowchart. Even in Mercurial, common commands like 'incoming' and 'outgoing' hit the server, whereas with Git you can 'fetch' all the servers data before going offline and do comparisons, merges and logs of data that is on the server but not in your local branches yet. This means that it's very easy to have copies of not only your branches, but also of everyone's branches that are working with you in your Git repository without having to mess your own stuff up. Git is Fast Git is fast. Everyone—even most of the hard core users of these other systems—generally give Git this title. With Git, all operations are performed locally giving it a bit of a leg up on SVN and Perforce, both of which require network access for certain operations. However, even compared to the other DSCMs that also perform operations locally, Git is pretty fast. Part of this is likely because it was built to work on the Linux kernel, which means that it has had to deal effectively with large repositories from day one. Additionally, Git is written in C, reducing the overhead of runtimes associated with higher-level languages. Another reason that Git is so fast is that the primary developers have made this a design goal of the application.

Git is Small Git is really good at conserving disk space. Your Git directory will (in general) barely be larger than an SVN checkout—in some cases actually smaller (apparently a lot can go in those .svn dirs). The following numbers were taken from clones of the Django [1]project in each of its semi-official Git mirrors at the same point in its history. Git Hg Bzr SVN Repo Alone 24M 34M 45M Entire Directory 43M 53M 64M 61M

The Staging Area Unlike the other systems, Git has what it calls the "staging area" or "index". This is an intermediate area that you can setup what you want your commit to look like before you commit it. The cool thing about the staging area, and what sets Git apart from all these other tools, is that you can easily stage some of your files as you finish them and then commit them without committing all the modified files in your working directory, or having to list them on the command line during the commit add commit workflow diagram This also allows you to stage only portions of a modified file. Gone are the days of making two logically unrelated modifications to a file before you realized that you forgot to commit one of them. Now you can just stage the change you need for the current commit and stage the other change for the next commit. This feature scales up to as many different changes to your file as you need. Of course, Git also makes it pretty easy to ignore this feature if you don't want that kind of control—just slap a '-a' to your commit command in order to add all changes to all files to the staging area. commit only workflow diagram

Distributed One of the coolest features of any of the Distributed SCMs, Git included, is that it's distributed. This means that instead of doing a "checkout" of the current tip of the source code, you do a "clone" of the entire repository. This means that even if you're using a centralized workflow, every user has what is essentially a full backup of the main server, each of which could be pushed up to replace the main server in the event of a crash or corruption. There is basically no single point of failure with Git unless there is only a single point. This does not slow things down much, either. On average, an SVN checkout is only marginally faster than any of the DSCMs. Of the DSCMs I tested, Git was the fastest. cloning benchmarks Git 1m 59s Hg 2m 24s Bzr 5m 11s SVN 1m 4s

Any Workflow One of the amazing things about Git is that because of its distributed nature and super branching system, you can easily implement pretty much any workflow you can think of relatively easily. Subversion-Style Workflow A very common Git workflow, especially from people transitioning from a centralized system, is a centralized workflow. Git will not allow you to push if someone has pushed since the last time you fetched, so a centralized model where all developers push to the same server works just fine. subversion-style workflow

Integration Manager Workflow

Another common Git workflow is where there is an integration manager—a single person who commits to the 'blessed' repository, and then a number of developers who clone from that repository, push to their own independent repositories and ask the integrator to pull in their changes. This is the type of development model you often see with open source or GitHub repositories. integration manager workflow Dictator and Lieutenants Workflow

For more massive projects, you can setup your developers similar to the way the Linux kernel is run, where people are in charge of a specific subsystem of the project ('lieutenants') and merge in all changes that have to do with that subsystem. Then another integrator (the 'dictator') can pull changes from only his/her lieutenants and push those to the 'blessed' repository that everyone then clones from again.




Git Work Flow

Hello

Test test


test


Test


Test

Test

Test

Test Check


Test


Test

Characteristics of Git

Strong support for non-linear development
Git supports rapid and convenient branching and merging, and includes powerful tools for visualizing and navigating a non-linear development history.
Distributed development
Like most other modern version control systems, Git gives each developer a local copy of the entire development history, and changes are copied from one such repository to another. These changes are imported as additional development branches, and can be merged in the same way as a locally developed branch. Repositories can be easily accessed via the efficient Git protocol (optionally wrapped in ssh for authentication and security) or simply using HTTP - you can publish your repository anywhere without any special webserver configuration required.
Efficient handling of large projects
Git is very fast and scales well even when working with large projects and long histories. It is commonly an order of magnitude faster than most other version control systems, and several orders of magnitude faster on some operations. It also uses an extremely efficient packed format for long-term revision storage that currently tops any other open source version control system.
Cryptographic authentication of history
The Git history is stored in such a way that the name of a particular revision (a "commit" in Git terms) depends upon the complete development history leading up to that commit. Once it is published, it is not possible to change the old versions without it being noticed. Also, tags can be cryptographically signed.
Toolkit-based design
Following the Unix tradition, Git is a collection of many small tools written in C, and a number of scripts that provide convenient wrappers. Git provides tools for both convenient human usage and easy scripting to perform new clever operations.

How do I use Git?

Every commit that a user makes will have his/her name and email address to identify the ‘owner’ of the commit, so the user should give these values in a form of configuration.

git config --global user.name "Your Name"
git config --global user.email "your@email.com"

To get started with Git, a user needs to run the git init command in an empty directory; this initializes a Git repository in that folder, adding a .git folder within it. A repository is kind of like a code history book. It will hold all the past versions of your code, as well as the current one.

git init

A project managed by Git can be considered as a tree; a user can create different features on different branches, and everything will stay separate and safe. After the user has created new files in the repository. It is time to commit these files to mark the completion of feature development and ready to push changes to remote repository. However, before that, the user needs to add the files and move it to staging area.

git add .

A user can also more specifically add files.

git add *.js
git add index.php

This will add all the files to staging area. To stage is simply to prepare it finely for a commit. Git, with its index allows you to commit only certain parts of the changes you've done since the last commit.

After a user has staged the required files, they need to commit the files by giving a commit description.

git commit -m "Commit description"

Each commit should have an accompanying message, so everyone in the project knows why that code was committed. A user can also skip the command to add the files in the staging area by directly asking Git to stage and commit with a message.

git commit -am "Commit description"

Git uses the code contents of the commit to create a 40 character SHA1 hash. The neat part about this is that, since it's using the code to create the hash, no two hashes in the user's project will be the same unless the code in the commits is identical. A user can check the status of the git repository by the following command.

git status

To push the changes to a remote git repository, a user can do a git push as following.

git push origin master