Slide 1

Slide 1 text

Dmitry Sheiko @sheiko A Quick Start – Version Control with Git

Slide 2

Slide 2 text

What is Git?

Slide 3

Slide 3 text

Why do people love Git?

Slide 4

Slide 4 text

How is Git distributed?

Slide 5

Slide 5 text

What does Git give us? repo repo repo repo repo repo repo repo

Slide 6

Slide 6 text

Git branching model Master branch Hotfixes Dev. branch Release 1.0 Feature branches TIME Tag 0.1 Tag 0.2 Tag 1.0

Slide 7

Slide 7 text

How to begin using Git?

Slide 8

Slide 8 text

Installation

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

Initialization $cd /l/vhosts/os.htdocs/example $ls $git init Go to the source code Are we really there? Create Git repository

Slide 11

Slide 11 text

Fork existing repository $git clone git://github.com/dsheiko/HTML5-Form- Shim.git

Slide 12

Slide 12 text

Commit $git commit –am “comment”

Slide 13

Slide 13 text

Status $git status

Slide 14

Slide 14 text

Reverting $git log $git checkout 64fd65b9194b108643e267795f9442ca9e61631f Get revisions ids Use one

Slide 15

Slide 15 text

Resetting $git reset HEAD --hard

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

Rebase $git log $git rebase -i HEAD~7 Take a look what revisions we have Combine the last 7 revisions

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

Log We can see our commit history $git log --graph .. and much fancier $gitk --all

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

Who’s the dude? http://dsheiko.com @sheiko https://github.com/dsheiko