Upload
gaplabs
View
190
Download
0
Tags:
Embed Size (px)
Citation preview
Feb. 23, 2013
Version ControlBasics of Git
References:http://gitref.org
http://git-scm.com
Feb. 23, 2013
Outline• What is Version Control• Why Version Control• Git as Version Control Tool
Feb. 23, 2013
What
Feb. 23, 2013
What Version Control
Feb. 23, 2013
What Version Control
lets you track your files
Feb. 23, 2013
What Version Control
lets you track your files
so when you mess up you can easily get back to a previous working version
Feb. 23, 2013
Why
Feb. 23, 2013
Why• Backup and Restore
Feb. 23, 2013
Why• Backup and Restore• Synchronization
Feb. 23, 2013
Why• Backup and Restore• Synchronization• Track Changes
Feb. 23, 2013
Why• Backup and Restore• Synchronization• Track Changes• Track Ownership
Feb. 23, 2013
How• Repository
where files are being stored
• Local Repositoryrepository in the local machine
• Remote Repositoryare versions of your project that are hosted over the Internet or network somewhere
Feb. 23, 2013
Git: Basics
Feb. 23, 2013
Git: Basics• Get / Create Repository
Feb. 23, 2013
Git: Basics• Get / Create Repository
• Record Changes
Feb. 23, 2013
Git: Basics• Get / Create Repository
• Record Changes
• Track History
Feb. 23, 2013
Git: Basics• Get / Create Repository
• Record Changes
• Track History
• Undo Things
Feb. 23, 2013
Git: Basics• Get / Create Repository
• Record Changes
• Track History
• Undo Things
• Sharing / Updating Files
Feb. 23, 2013
working directory
remote repolocal repo
staging area
git-add git-commit git-push
git-fetch
git-checkout
git-reset
git-pull
git-diff
git-diff --staged
git-clone
Feb. 23, 2013
Feb. 23, 2013
Create / Get
Feb. 23, 2013
Create / Get
• get remote repository
Feb. 23, 2013
Create / Get
• get remote repository git clone [repository url] [destination]
Feb. 23, 2013
Create / Get
• get remote repository git clone [repository url] [destination]
• existing directory
Feb. 23, 2013
Create / Get
• get remote repository git clone [repository url] [destination]
• existing directory git init [path/to/directory|file]
Feb. 23, 2013
Record Changes
Feb. 23, 2013
Record Changes
• Tracked Files
Feb. 23, 2013
Record Changes
• Tracked FilesFi les that are currently in the repository
Feb. 23, 2013
Record Changes
• Tracked FilesFi les that are currently in the repository
- unmodified, modified, staged
Feb. 23, 2013
Record Changes
• Tracked FilesFi les that are currently in the repository
- unmodified, modified, staged
• Untracked Files
Feb. 23, 2013
Record Changes
• Tracked FilesFi les that are currently in the repository
- unmodified, modified, staged
• Untracked Files Everything else
Feb. 23, 2013
Tracking New Files
Feb. 23, 2013
Tracking New Filesgit add [path/to/file|directory]
Feb. 23, 2013
Tracking New Filesgit add [path/to/file|directory]
git-add command adds files to the staging area
Feb. 23, 2013
Committing Staged Files
Feb. 23, 2013
Committing Staged Files
git commit -m "message"
Feb. 23, 2013
Committing Staged Files
git commit -m "message"
git-commit command commits all staged files
Feb. 23, 2013
Ignoring Files
Feb. 23, 2013
Ignoring Files• Blank lines or lines starting with # are ignored.
Feb. 23, 2013
Ignoring Files• Blank lines or lines starting with # are ignored.
• Standard glob patterns work.
Feb. 23, 2013
Ignoring Files• Blank lines or lines starting with # are ignored.
• Standard glob patterns work.
• You can end patterns with a forward slash (/) to specify a directory.
Feb. 23, 2013
Ignoring Files• Blank lines or lines starting with # are ignored.
• Standard glob patterns work.
• You can end patterns with a forward slash (/) to specify a directory.• You can negate a pattern by starting it with an exclamation point (!).
Feb. 23, 2013
Staged and Unstaged Changes
Feb. 23, 2013
Staged and Unstaged Changes
git diff
Feb. 23, 2013
Staged and Unstaged Changes
git diff shows diff of what is modified but unstaged
Feb. 23, 2013
Staged and Unstaged Changes
git diff shows diff of what is modified but unstaged
git diff --staged
Feb. 23, 2013
Staged and Unstaged Changes
git diff shows diff of what is modified but unstaged
git diff --stagedshows the changes that will currently go into the next commit.
Feb. 23, 2013
Removing Files
Renaming Files
Tracking History
Feb. 23, 2013
Removing Filesgit rm [file/directory]
Renaming Files
Tracking History
Feb. 23, 2013
Removing Filesgit rm [file/directory]
git mv current_file_name new_file_name
Renaming Files
Tracking History
Feb. 23, 2013
Removing Filesgit rm [file/directory]
git mv current_file_name new_file_name
Renaming Files
Tracking Historygit log
Feb. 23, 2013
Undoing Things
Feb. 23, 2013
Undoing Things• Unstaging staged file
Feb. 23, 2013
Undoing Things• Unstaging staged file
git reset HEAD <file>
Feb. 23, 2013
Undoing Things• Unstaging staged file
git reset HEAD <file>
• Unmodifying modified file
Feb. 23, 2013
Undoing Things• Unstaging staged file
git reset HEAD <file>
• Unmodifying modified file git checkout -- <file>
Feb. 23, 2013
Undoing Things
These commands are actually suggested when running git-status command
• Unstaging staged filegit reset HEAD <file>
• Unmodifying modified file git checkout -- <file>
Feb. 23, 2013
Sharing / Updating Files
Feb. 23, 2013
Sharing / Updating FilesRemote Repositories
Feb. 23, 2013
Sharing / Updating FilesRemote Repositories
are versions of your project that are hosted over the Internet or network somewhere.
Feb. 23, 2013
Sharing / Updating FilesRemote Repositories
are versions of your project that are hosted over the Internet or network somewhere.
• Show remote repository
Feb. 23, 2013
Sharing / Updating FilesRemote Repositories
are versions of your project that are hosted over the Internet or network somewhere.
• Show remote repository• Add remote repository
Feb. 23, 2013
Sharing / Updating FilesRemote Repositories
are versions of your project that are hosted over the Internet or network somewhere.
• Show remote repository• Add remote repository• Update/Sync remote repository
Feb. 23, 2013
Sharing / Updating FilesRemote Repositories
are versions of your project that are hosted over the Internet or network somewhere.
• Show remote repository• Add remote repository• Update/Sync remote repository• Inspect remote repository
Feb. 23, 2013
Remote Repository
Feb. 23, 2013
Remote Repository• Show remote repository
Feb. 23, 2013
Remote Repository• Show remote repository
git remote -v
Feb. 23, 2013
Remote Repository• Show remote repository
git remote -v• Add remote repository
Feb. 23, 2013
Remote Repository• Show remote repository
git remote -v• Add remote repository
git remote add [alias] [repository url]
Feb. 23, 2013
Remote Repository• Show remote repository
git remote -v• Add remote repository
git remote add [alias] [repository url]• Update remote repository
Feb. 23, 2013
Remote Repository• Show remote repository
git remote -v• Add remote repository
git remote add [alias] [repository url]• Update remote repository
git push [alias] [branch]
Feb. 23, 2013
Remote Repository• Show remote repository
git remote -v• Add remote repository
git remote add [alias] [repository url]• Update remote repository
git push [alias] [branch]• Sync with remote
Feb. 23, 2013
Remote Repository• Show remote repository
git remote -v• Add remote repository
git remote add [alias] [repository url]• Update remote repository
git push [alias] [branch]• Sync with remote
git pull [alias] [branch]
Feb. 23, 2013
Remote Repository• Show remote repository
git remote -v• Add remote repository
git remote add [alias] [repository url]• Update remote repository
git push [alias] [branch]• Sync with remote
git pull [alias] [branch]• Inspect remote repository
Feb. 23, 2013
Remote Repository• Show remote repository
git remote -v• Add remote repository
git remote add [alias] [repository url]• Update remote repository
git push [alias] [branch]• Sync with remote
git pull [alias] [branch]• Inspect remote repository
git remote show [alias]