getting started with git: a primer for svn and tfs users

23
Getting Started with Git a primer for svn and tfs users Noam Kfir | Sela Group | 2014

Upload: noam-kfir

Post on 27-Jun-2015

375 views

Category:

Technology


1 download

DESCRIPTION

I gave this presentation at the Israeli ALM User Group. This is part 1 of a 2 part series on Git and Git workflows and introduces the most basic Git functionality, especially as it differs from the Subversion and TFS version control systems.

TRANSCRIPT

Page 1: Getting Started with Git: A Primer for SVN and TFS Users

Getting Started with Gita primer for svn and tfs users

Noam Kfir | Sela Group | 2014

Page 2: Getting Started with Git: A Primer for SVN and TFS Users

Agenda

VCS Overview

Git in a Nutshell

Q&A

Page 3: Getting Started with Git: A Primer for SVN and TFS Users

Version Control Systems (VCS)

• Backup code and other resources• Restore previous statesReversibility

• Share with the team• Make available to automated

processesConcurrency

• Comments, tags and other metadata• CommunicationAnnotation

Page 4: Getting Started with Git: A Primer for SVN and TFS Users

Approaches to Version Control

CentralizedOne Authority

Connected

File System*

DistributedArbitrary Authority

Disconnected

Database

Page 5: Getting Started with Git: A Primer for SVN and TFS Users

Basic Product Comparison

TFSWorkspace

Changesets

One stage:check in

SVNWorking Copy

Changesets

One stage:commit

GitFull Repository

Snapshots

Two stages:commit + push

Page 6: Getting Started with Git: A Primer for SVN and TFS Users

Commits Are Local

Modify only the local repository index Do not modify the remote repository

Every commit: Creates a snapshot

Creates a new revision

Receives a new unique SHA-1 ref identifier

Supports completely disconnected workflows

Page 7: Getting Started with Git: A Primer for SVN and TFS Users

More Advantages of Local Commits

Can accumulate multiple commits before integrating

Easier to group related commits

History can be cleaned up before pushing changes

More control over local environment

Page 8: Getting Started with Git: A Primer for SVN and TFS Users

Snapshots over Deltas

Faster operations

Complex merges

Rewriting history

Advanced workflows

Page 9: Getting Started with Git: A Primer for SVN and TFS Users

Installing Git on Windows

http://git-scm.com

Chocolatey: cinst git

TortoiseGit

GitExtensions

Visual Studio Team Explorer

And many more…

Page 10: Getting Started with Git: A Primer for SVN and TFS Users

Configuration

Configuration Cascade local per repository

global per user

system per machine

Most common configurations are global

Some basic settings user.name

user.email

core.autocrlf

Page 11: Getting Started with Git: A Primer for SVN and TFS Users

Excluding Files and Folders

Avoid storing user-specific and temporary files in the remote repository,by using the .gitignore file

The .gitignore file supports wildcards

Ignored files do not appear in the git status command output

Page 12: Getting Started with Git: A Primer for SVN and TFS Users

Getting Started

git init repository-name Create a new repository

git remote add name url Link the local repository to a remote repository

git clone repository-url Copy and link an existing remote repository

Page 13: Getting Started with Git: A Primer for SVN and TFS Users

Bare Repositories

No working folder

Contents nearly identical to non-bare .git folder

By convention, .git extension appended to bare repository name

Created with git init --bare or git clone repository --bare

Central repositories are almost always bare

Local repositories are almost never bare

Page 14: Getting Started with Git: A Primer for SVN and TFS Users

Branches

A branch in Git points to a commit

It is not a container or a folder that stores files

git checkout [-b] branch Switch to the specified branch [after creating it]

git branch List and manage branches

Page 15: Getting Started with Git: A Primer for SVN and TFS Users

Revision Selection and refs

Git uses special files to store information about its history

Every commit has a SHA-1 identifier – called the ref

You can refer to any commit, including remote commits, using the ref or a shorter ref

The revision selection syntax is very flexible. A few examples: HEAD~1

HEAD^^

master..branch

a1b2c3d

Page 16: Getting Started with Git: A Primer for SVN and TFS Users

The Stage

Files ready to be committed are “on the stage”

Supports precise atomic commits – files and individual changes

git add files Stage files and/or changes to be committed

git status See an overview of the local changes

git commit -m message Create a commit with the staged changes

Some commands use the --cached parameter to refer to the stage

Page 17: Getting Started with Git: A Primer for SVN and TFS Users

Working with Remote Repositories

git pull repository Fetch and merge git fetch repository Fetch the latest version from the remote

repository

git merge source-branch Merge the changes from the specified branch

git push repository Send the local commits to the remote repository

Page 18: Getting Started with Git: A Primer for SVN and TFS Users

The Edit/Stage/Commit Sequence

git pull

(modify files)

git add file_or_folder

git status

git commit –m "Modified something or other”

git push

Page 19: Getting Started with Git: A Primer for SVN and TFS Users

Merge Without Fear

Merging is central to git

Different types of merge strategies Usually selected automatically

Can be specified manually

pull = fetch + merge

Page 20: Getting Started with Git: A Primer for SVN and TFS Users

Merge vs. Rebase

git merge

Copy

Adds to history

Usually safe

Good for traceability

Leaves messy history

git rebase

Move

Rewrites history

Can be dangerous

Good for cleanup

Makes history more linear

Page 21: Getting Started with Git: A Primer for SVN and TFS Users

Rich Featureset

Stash Log Branches

refspec

Merge Algorithms Aliases grep Tags

Hooks .gitignore

cherry-pick reflog

reset revert Patches Remotes

Page 22: Getting Started with Git: A Primer for SVN and TFS Users

Summary

Git is a very rich distributed version control system

Its distributed snapshot nature makes it extremely flexible and suitablefor many different types of work environments From individual programmers to small co-located teams to massive distributed teams

From open source projects to corporations

Git supported most of the workflows supported by TFS and SVN,but also offers additional benefits

Page 23: Getting Started with Git: A Primer for SVN and TFS Users

Thank You!