Outline
Who is behind Deveo?
Introduction to Version Control Systems
Basics of Git
Demo
Exercises
Who is behind Deveo?
Eficode in brief
Founded in 2005, privately owned 80 employees Offices in Helsinki, Beijing, and Copenhagen ISO 9001:2008 certified management system AAA-credit rating
How to manage source code?
Why Version Control (VCS)?
VCS manages changes to documents, source code, etc. – time machine
VCS allows a group of people to simultaneously collaborate on the
same files - feedback
VCS may act as a disaster recovery strategy - backup
Centralized VS Distributed
Central repository on a server
Send/receive changes from the central server
Single point of failure
Every developer has own mirror of repository
Send/receive changes to own repository
Continue working offline and share changes later
Git is a Distributed VCS with an emphasis on speed - fast
Speed Simple design Network independent Strong support for non-linear development Fully distributed Efficiently handles large projects Open source
Git VS “other systems”
Snapshots – not Differences
file A
file B
Version 1 Version 2 Version 3
1 2
1
file A
file B
Version 1 Version 2 Version 3
file A2 file A3
file B file B1 snapshot
Nearly every Git operation is local
Git guarantees data integrity
74262eab53b5f3ee4d578e484436e1ca72c57625
The three local states of Git
working directory
staging area
git repository
checkout the sources
stage files
commit
Installing and configuring Git http://progit.org/book/ch1-4.html
$ git config --global user.name "Tair Assimov"$ git config --global user.email "[email protected]"
Basic workflow
Create initclone
Browse statuslogdiff
Stage add
reset
Save commit
Modify vimmate
Sync pushpull
$ git init$ touch README$ git add README$ git commit -m 'initial project version'
Basic Workflow: Initializing
Basic Workflow: Cloning
$ git clone https://emea.deveo.com/eficode/git/project$ git clone [email protected]:eficode/git/project$ git clone /var/db/eficode/git/project
Basic workflow
Create initclone
Browse statuslogdiff
Stage add
reset
Save commit
Modify vimmate
Sync pushpull
Basic Workflow: Modify $ mate hello_git.rb$ echo "A Hello Git program" >> README
#!/usr/bin/env rubyclass HelloGit def initialize(git = '/usr/bin/git') @git = git end def to_s "Hello, from #{%x[#{@git} --version]}!" end endhello = HelloGit.newputs hello.to_s
working directory
staging area
git repository
Basic workflow
Create initclone
Browse statuslogdiff
Stage add
reset
Save commit
Modify vimmate
Sync pushpull
Basic Workflow: Browse $ git status
# On branch master# Changes not staged for commit:## modified: README## Untracked files:## hello_git.rbno changes added to commit (use "git add" and/or "git commit -a")
Basic workflow
Create initclone
Browse statuslogdiff
Stage add
reset
Save commit
Modify vimmate
Sync pushpull
Basic Workflow: Stage $ git add hello_git.rb
# On branch master# Changes to be committed:## new file: hello_git.rb## Changes not staged for commit:## modified: README
working directory
staging area
git repository
Basic Workflow: Stage $ git add .
$ git status# On branch master# Changes to be committed: <- STAGED## modified: README# new file: hello_git.rb
working directory
staging area
git repository
Basic Workflow: Unstage $ touch temp.swp$ git add .$ git status# On branch master# Changes to be committed:# (use "git reset HEAD <file>..." to unstage)## new file: temp.swp$ git reset HEAD temp.swp
git repository
working directory
staging area
Basic workflow
Create initclone
Browse statuslogdiff
Stage add
reset
Save commit
Modify vimmate
Sync pushpull
Basic Workflow: Save $ git commit
working directory
staging area
git repository
[master 1bfac9e] Descriptive summary of a commit 2 files changed, 17 insertions(+), 0 deletions(-) create mode 100755 hello_git.rb
Hold on, what was that number? [master 1bfac9e]
1bfac9eacb671e7916b64c5680c37264e1413ac0
$ git log
commit 1bfac9eacb671e7916b64c5680c37264e1413ac0Author: Tair Assimov <[email protected]>Date: Mon Apr 23 19:22:01 2012 +0300 Descriptive summary of a commit...
Basic workflow
Create initclone
Browse statuslogdiff
Stage add
reset
Save commit
Modify vimmate
Sync pushpull
Basic Workflow: Modify and Browse $ mate README$ git diff
diff --git a/README b/READMEindex 5710088..830c0c7 100644--- a/README+++ b/README@@ -1 +1,2 @@-A Hello Git program+A Hello Git program to print out version+of the Git binary.
working directory
staging area
git repository
Basic workflow
Create initclone
Browse statuslogdiff
Stage add
reset
Save commit
Modify vimmate
Sync pushpull
Basic Workflow: Stage and Commit $ git status
# On branch master# Changes not staged for commit:# # modified: README
working directory
staging area
git repository $ git commit -a -m "Update README"
[master 2b1e925] Update README 1 files changed, 2 insertions(+), 1 deletions(-)
More Git goodies…
Ignoring files
Ignoring files == Not tracking with Git Ignore temporary files, sensitive files Create .gitignore file in the root of the project Standard blob patterns work
Ignoring files
$ cat .gitignore# this is a comment*~ # ignore all files that end with tilde*.swp # ignore all files with .swp extension!t.swp # but track t.swp/tmp # ignore /tmp file or directorydoc/*.txt # ignore doc/notes.txt, but not doc/server/arch.txt
Removing files without Git
$ rm README$ git status# Changes not staged for commit:# # deleted: README$ git add -u$ git status# Changes to be committed:## deleted: README
Removing files with Git
$ git rm README$ git status# On branch master# Changes to be committed:## deleted: README
Removing files / Untracking
$ git rm --cached README$ git status# On branch master# Changes to be committed:## deleted: README## Untracked files:## README
Moving files without Git
$ mv README README.txt$ git status# On branch master# Changes to be committed:## deleted: README## Untracked files:## README
Moving files with Git
$ git mv README README.txt$ git status# On branch master# Changes to be committed:## renamed: README -> README.txt
Viewing Commit History
$ git log -p$ git log -stat$ git log --pretty=oneline$ git log --since=1.day$ git log --pretty=oneline --author=Tair --since=1.week
Undoing things - Amending
$ git commit -m 'initial commit’$ git add forgotten_file$ git commit --amend
Undoing things - Unmodifying $ git status# On branch master# Changes not staged for commit:# (use "git add <file>..." to update what will be committed)# (use "git checkout -- <file>..." to discard changes in working directory)## modified: hello_git.rb
$ git checkout -- hello_git.rb
Git remotes
Create initclone
Browse statuslogdiff
Stage add
reset
Save commit
Modify vimmate
Sync pushpull
VCS allows a group of people to simultaneously collaborate on the
same files - feedback
Online project hosting
Hosting tools streamline collaborative development Find, publish, and contribute to Open Source software Reliable, robust and backed up
Deveo is a software development platform, which collects information
into one, easily accessible place
Documentation
Version control Continuous Integration
Developers
Project Manager
Testing
Executive
Communication
Task management
Demo
Cloning existing repository
$ git clone https://emea.deveo.com/.../git/repoCloning into repo...remote: Counting objects: 10, done.remote: Compressing objects: 100% (7/7), done.remote: Total 10 (delta 0), reused 0 (delta 0)Unpacking objects: 100% (10/10), done.
Showing remotes
$ git remoteorigin$ git remote –voriginhttps://emea.deveo.com/.../git/repo (fetch)originhttps://emea.deveo.com/.../git/repo (push)another [email protected]:eficode/.../git/repo
Adding remote
$ git remote add origin https://emea.deveo.com/.../git/repo$ git remote add upstream https://emea.deveo.com/.../git/repo
Fetching and Pulling from remotes
$ git fetch anotherFrom https://emea.deveo.com/.../git/repo * [new branch] master -> another/master$ git pull
Pushing changes to remote
$ git push origin master
Removing and renaming remotes
$ git remote rename another another_origin$ git remoteanother_originorigin$ git remote rm another_origin$ git remoteorigin
Branching and Merging
What is a Branch?
Branch in Git is a lightweight movable pointer to one of the commits
commit 1 commit 2 commit 3
master
$ git branch feature
What if you create a new Branch?
commit 1 commit 2 commit 3
master
feature
Where are you now?
commit 1 commit 2 commit 3
master
feature
HEAD
Switch to a branch
$ git checkout feature$ git checkout -b feature # creates a branch and switches to it
commit 1 commit 2 commit 3
master
feature
HEAD
Commit to feature branch
$ git commit -a -m "New feature. Initial commit"
commit 1 commit 2 commit 3
master
feature
HEAD
commit 4
Checkout master
$ git checkout master
commit 1 commit 2 commit 3
master
feature
HEAD
commit 4
Commit to master
$ git commit -a -m "Master diverged"
commit 1 commit 2 commit 3
master
feature
HEAD
commit 4
commit 5
Getting Help
http://progit.org
Top Related