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.
3. Version Control Systems (VCS)
•Backup code and other resources
• Restore previous states Reversibility
•Share with the team
•Make available to automated processes Concurrency
•Comments, tags and other metadata
•Communication Annotation
4. Approaches to Version Control
Centralized
One Authority
Connected
File System*
Distributed
Arbitrary Authority
Disconnected
Database
5. Basic Product Comparison
TFS
Workspace
Changesets
One stage:
check in
SVN
Working Copy
Changesets
One stage:
commit
Git
Full Repository
Snapshots
Two stages:
commit + push
6. 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
7. 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
8. Snapshots over Deltas
Faster
operations
Complex
merges
Rewriting
history
Advanced
workflows
9. Installing Git on Windows
http://git-scm.com
Chocolatey: cinst git
TortoiseGit
GitExtensions
Visual Studio Team Explorer
And many more…
10. 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
11. 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
12. 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
13. 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
14. 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
15. 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
16. 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
17. 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
18. 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
19. Merge Without Fear
Merging is central to git
Different types of merge strategies
Usually selected automatically
Can be specified manually
pull = fetch + merge
20. 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
22. Summary
Git is a very rich distributed version control system
Its distributed snapshot nature makes it extremely flexible and suitable
for 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