Download - A Quick Start - Version Control with Git
![Page 1: A Quick Start - Version Control with Git](https://reader036.vdocuments.us/reader036/viewer/2022062703/5551994eb4c905013a8b4af5/html5/thumbnails/1.jpg)
Dmitry Sheiko
@sheiko
A Quick Start – Version Control with Git
![Page 2: A Quick Start - Version Control with Git](https://reader036.vdocuments.us/reader036/viewer/2022062703/5551994eb4c905013a8b4af5/html5/thumbnails/2.jpg)
What is Git?
![Page 3: A Quick Start - Version Control with Git](https://reader036.vdocuments.us/reader036/viewer/2022062703/5551994eb4c905013a8b4af5/html5/thumbnails/3.jpg)
Why do people love Git?
![Page 4: A Quick Start - Version Control with Git](https://reader036.vdocuments.us/reader036/viewer/2022062703/5551994eb4c905013a8b4af5/html5/thumbnails/4.jpg)
How is Git distributed?
![Page 5: A Quick Start - Version Control with Git](https://reader036.vdocuments.us/reader036/viewer/2022062703/5551994eb4c905013a8b4af5/html5/thumbnails/5.jpg)
What does Git give us?
repo
repo
repo
repo
repo
repo
repo
repo
![Page 6: A Quick Start - Version Control with Git](https://reader036.vdocuments.us/reader036/viewer/2022062703/5551994eb4c905013a8b4af5/html5/thumbnails/6.jpg)
Git branching model
Master branch
Hotfixes
Dev. branch
Release 1.0
Feature branches
TIME
Tag 0.1 Tag 0.2 Tag 1.0
![Page 7: A Quick Start - Version Control with Git](https://reader036.vdocuments.us/reader036/viewer/2022062703/5551994eb4c905013a8b4af5/html5/thumbnails/7.jpg)
How to begin using Git?
![Page 8: A Quick Start - Version Control with Git](https://reader036.vdocuments.us/reader036/viewer/2022062703/5551994eb4c905013a8b4af5/html5/thumbnails/8.jpg)
Installation
![Page 9: A Quick Start - Version Control with Git](https://reader036.vdocuments.us/reader036/viewer/2022062703/5551994eb4c905013a8b4af5/html5/thumbnails/9.jpg)
Setup
$git config --global user.name "Your Name" $git config --global user.email "[email protected]" $git config --global color.diff auto $git config --global color.status auto $git config --global color.branch auto
![Page 10: A Quick Start - Version Control with Git](https://reader036.vdocuments.us/reader036/viewer/2022062703/5551994eb4c905013a8b4af5/html5/thumbnails/10.jpg)
Initialization
$cd /l/vhosts/os.htdocs/example $ls $git init
Go to the source code
Are we really there?
Create Git repository
![Page 11: A Quick Start - Version Control with Git](https://reader036.vdocuments.us/reader036/viewer/2022062703/5551994eb4c905013a8b4af5/html5/thumbnails/11.jpg)
Fork existing repository
$git clone git://github.com/dsheiko/HTML5-Form-Shim.git
![Page 12: A Quick Start - Version Control with Git](https://reader036.vdocuments.us/reader036/viewer/2022062703/5551994eb4c905013a8b4af5/html5/thumbnails/12.jpg)
Commit
$git commit –am “comment”
![Page 13: A Quick Start - Version Control with Git](https://reader036.vdocuments.us/reader036/viewer/2022062703/5551994eb4c905013a8b4af5/html5/thumbnails/13.jpg)
Status
$git status
![Page 14: A Quick Start - Version Control with Git](https://reader036.vdocuments.us/reader036/viewer/2022062703/5551994eb4c905013a8b4af5/html5/thumbnails/14.jpg)
Reverting
$git log $git checkout 64fd65b9194b108643e267795f9442ca9e61631f
Get revisions ids
Use one
![Page 15: A Quick Start - Version Control with Git](https://reader036.vdocuments.us/reader036/viewer/2022062703/5551994eb4c905013a8b4af5/html5/thumbnails/15.jpg)
Resetting
$git reset HEAD --hard
![Page 16: A Quick Start - Version Control with Git](https://reader036.vdocuments.us/reader036/viewer/2022062703/5551994eb4c905013a8b4af5/html5/thumbnails/16.jpg)
Branching
If we have a new feature request, which implementation concerns much of the source code, it would be safer to work on the feature in a separate branch.
$git branch Feature1022 –m “Comment” $git checkout Feature1022 $git branch
Create a branch
Switch to the branch
Show available branches
![Page 17: A Quick Start - Version Control with Git](https://reader036.vdocuments.us/reader036/viewer/2022062703/5551994eb4c905013a8b4af5/html5/thumbnails/17.jpg)
Rebase
$git log $git rebase -i HEAD~7
Take a look what revisions we have
Combine the last 7 revisions
![Page 18: A Quick Start - Version Control with Git](https://reader036.vdocuments.us/reader036/viewer/2022062703/5551994eb4c905013a8b4af5/html5/thumbnails/18.jpg)
Merging
As we finished the requested feature development, we can merge the feature branch with the master branch
$git checkout master $git merge Feature1022 $git branch -d Feature1022
Master branch
Feature1022
Switch to the master branch
Get rid of the feature branch
![Page 19: A Quick Start - Version Control with Git](https://reader036.vdocuments.us/reader036/viewer/2022062703/5551994eb4c905013a8b4af5/html5/thumbnails/19.jpg)
Tagging
We can tag specific points in history as being important. E.g. tag every stable version of the product before deploying.
$git tag v1.1 –m “Comment” $git checkout tags/v1.1 $git tag $git tag –d v.1.1 $git push remote :refs/tags/v.1.1
Create a tag
Switch to the tag
Show available tags
Remote tag in local repo
Remote tag in remote repo
![Page 20: A Quick Start - Version Control with Git](https://reader036.vdocuments.us/reader036/viewer/2022062703/5551994eb4c905013a8b4af5/html5/thumbnails/20.jpg)
Log
We can see our commit history
$git log --graph
.. and much fancier
$gitk --all
![Page 21: A Quick Start - Version Control with Git](https://reader036.vdocuments.us/reader036/viewer/2022062703/5551994eb4c905013a8b4af5/html5/thumbnails/21.jpg)
Working with a remote repo
Let’s associate our local repo to the new created remote repo
$cd /repos/example-remote $git init --bare
$cd /l/vhosts/os.htdocs/example $git remote add origin /repos/example-remote
![Page 22: A Quick Start - Version Control with Git](https://reader036.vdocuments.us/reader036/viewer/2022062703/5551994eb4c905013a8b4af5/html5/thumbnails/22.jpg)
Push changes to a remote repo
We can push our changes collected in the local repository to the remote one to share them with the team
$cd /l/vhosts/os.htdocs/example $git push origin master
Associated remote repo
Branch
![Page 23: A Quick Start - Version Control with Git](https://reader036.vdocuments.us/reader036/viewer/2022062703/5551994eb4c905013a8b4af5/html5/thumbnails/23.jpg)
Pull changes from a remote repo
Pull allows us to get the latest changes from the remote repository.
$cd /l/vhosts/os.htdocs/example $git pull origin master
![Page 24: A Quick Start - Version Control with Git](https://reader036.vdocuments.us/reader036/viewer/2022062703/5551994eb4c905013a8b4af5/html5/thumbnails/24.jpg)
Creating patches
Patch is a text file that contains changes to the source code. This file can be sent to someone else and this person can use this file to apply the changes to his/her local
$git checkout mybranch $git commit -am "First commit in the branch“ $git format-patch origin/master $git checkout master $git apply 0001-First-commit-in-the-branch.patch
Creates 0001-First-commit-in-the-branch.patch
![Page 25: A Quick Start - Version Control with Git](https://reader036.vdocuments.us/reader036/viewer/2022062703/5551994eb4c905013a8b4af5/html5/thumbnails/25.jpg)
Git command aliases
Put into .gitconfig anywhere in parent directory with following content:
[alias] cd = checkout dir = branch ci = commit -a -m lg = log -p undo = reset –hard up = !git push origin master && git push origin --tags
![Page 26: A Quick Start - Version Control with Git](https://reader036.vdocuments.us/reader036/viewer/2022062703/5551994eb4c905013a8b4af5/html5/thumbnails/26.jpg)
Git command aliases
Now you can use shortcuts:
$git cd SomeBranch $git dir $git ci “my comment“ $git up # this one pushes local commits and tags to the remote repo
![Page 27: A Quick Start - Version Control with Git](https://reader036.vdocuments.us/reader036/viewer/2022062703/5551994eb4c905013a8b4af5/html5/thumbnails/27.jpg)
Who’s the dude?
http://dsheiko.com
@sheiko
https://github.com/dsheiko