internal talk #2 – git – arkadiusz fal, xhtmlized, 2014

93
The Master of VCS Internal Talk #2 Arkadiusz Fal

Upload: arek-fal

Post on 25-Jan-2015

58 views

Category:

Engineering


2 download

DESCRIPTION

What is Git, how you use it and how to become a Git master.

TRANSCRIPT

Page 1: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

The Master of VCS !

Internal Talk #2Arkadiusz Fal

Page 2: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

What is Git

Page 3: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

revision control

Page 4: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

tracking changes

revision control

Page 5: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

tracking changescollaboration

revision control

Page 6: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

tracking changescollaboration

nothing will ever be gone

revision control

Page 7: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

tracking changescollaboration

nothing will ever be gonereverting changes

revision control

Page 8: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

tracking changescollaboration

nothing will ever be gonereverting changes

sharing code

revision control

Page 9: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

version control systems

Page 10: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

stand-alone applications built to manage versioning

!

!

version control systems

Page 11: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

stand-alone applications built to manage versioning

!

!

version control systems

Page 12: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

stand-alone applications built to manage versioning

!

!

version control systems

Page 13: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

stand-alone applications built to manage versioning

!

!

version control systems

Page 14: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

…but Git is better!

smaller, faster, feature-loaded !

http://thkoch2001.github.io/whygitisbetter/

Page 15: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

Git basics

Page 16: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

common tasks

git initcreates a new, empty Git repository

! > cd awesome-project > git init Initialized empty Git repository in /Users/Arek/awesome-project/.git/ !!!!!!!!!

Page 17: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

common tasks

git statusshows current repository status

! > edit index.php > git status On branch master ! Untracked files: (use "git add <file>..." to include in what will be committed) ! index.php ! nothing added to commit but untracked files present (use "git add" to track) !!

Page 18: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

common tasks

git add <file>marks file as tracked

! > git add index.php > git status On branch master ! Initial commit ! Changes to be committed: (use "git rm --cached <file>..." to unstage) ! new file: index.php !!

Page 19: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

common tasks

git commit -m “<message>”commits changes

! > git commit -m "Initial commit" [master (root-commit) 1a9925e] Initial commit 1 file changed, 22 insertions(+) create mode 100644 index.php ! > git status On branch master nothing to commit, working directory clean !!!!

Page 20: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

common tasks

git log shows commit history

! > git log commit 1a9925e4797490b874f6430b264164004356f8e6 Author: Arkadiusz Fal <[email protected]> Date: Sun Mar 30 15:50:54 2014 +0200 ! Initial commit !!!!!!

Page 21: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

common tasks

git diffshows changes in working directory

! > edit index.php > git diff diff --git a/index.php b/index.php index e6ad67b..68c9928 100644 --- a/index.php +++ b/index.php @@ -5,7 +5,7 @@ class Index { - private $twig; + protected $twig; !

Page 22: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

common tasks

Page 23: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

common tasks

git rm <file>removes file from index

Page 24: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

common tasks

git rm <file>removes file from index

git blame <file>shows line-by-line who created/edited file

Page 25: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

common tasks

git rm <file>removes file from index

git blame <file>shows line-by-line who created/edited file

Page 26: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

Coworking with Git

Page 27: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

Git remotes

Page 28: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

Git remotes

servers in the Internet that store and let manage repositories

Page 29: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

Git remotes

servers in the Internet that store and let manage repositories

Page 30: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

Git remotes

servers in the Internet that store and let manage repositories

Page 31: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

Git remotes

servers in the Internet that store and let manage repositories

Page 32: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

Git remotes

servers in the Internet that store and let manage repositories

Page 33: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

Git remotes

servers in the Internet that store and let manage repositories

…and many more

Page 34: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

git clonecreates a copy of existing repository

! > git clone [email protected]:gruntjs/grunt.git Cloning into 'grunt'... remote: Reusing existing pack: 8384, done. remote: Counting objects: 26, done. remote: Compressing objects: 100% (26/26), done. remote: Total 8410 (delta 15), reused 0 (delta 0) Receiving objects: 100% (8410/8410), 2.92 MiB | 946.00 KiB/s, done. Resolving deltas: 100% (3718/3718), done. Checking connectivity... done. !!!

collaboration with Git

Page 35: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

collaboration with Git

git remote add <name> <url>adds a remote server

! > git remote add origin [email protected]:arekf/awesome-project.git !!!!!!!!!!!

Page 36: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

git push <server>sends changes & commits to the server

! > git push origin Counting objects: 3, done. Delta compression using up to 4 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 401 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To [email protected]:arekf/awesome-project.git * [new branch] master -> master !!!!

collaboration with Git

Page 37: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

git push <server>sends changes & commits to the server

collaboration with Git

Page 38: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

git fetch asks the server if there are any changes pushed by others

! > git fetch remote: Counting objects: 5, done. remote: Compressing objects: 100% (1/1), done. remote: Total 3 (delta 1), reused 3 (delta 1) Unpacking objects: 100% (3/3), done. From github.com:arekf/awesome-project 1a9925e..80151a6 master -> origin/master !!!!!

collaboration with Git

Page 39: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

git fetch …but doesn’t update files contents

! > git status On branch master Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded. (use "git pull" to update your local branch) ! nothing to commit, working directory clean !!!!!!

collaboration with Git

Page 40: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

git pullmerges changes pushed by others

! > git pull Updating 1a9925e..80151a6 Fast-forward index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) !!!!!!!

collaboration with Git

Page 41: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

Branching

Page 42: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

branching

Page 43: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

Branch is a independent line of development. Has independent working

directory and history.

branching

Page 44: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

Branch is a independent line of development. Has independent working

directory and history.

Using branches, you can edit files inside them independently because changes made in one branch do not affect any

other branches.

branching

Page 45: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

branching

Page 46: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

branching

C1

Page 47: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

branching

C1

master

Page 48: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

branching

C1

master

C2

Page 49: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

branching

C1

master

C2

Page 50: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

branching

C1

master

C2

feature

Page 51: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

branching

C1

master

C2

feature

C3

Page 52: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

branching

C1

master

C2

feature

C3

Page 53: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

git checkout -b <name>creates branch with current branch contents

! > git checkout -b feature Switched to a new branch 'feature' !!!!!!!!!!

branching

Page 54: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

git checkout <name>switches to other branch

! > git checkout master Switched to branch 'master' Your branch is up-to-date with 'origin/master'. !!!!!!!!!

branching

Page 55: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

git push <server> <branch>pushes branch contents to the server

! > git push origin feature Total 0 (delta 0), reused 0 (delta 0) To [email protected]:arekf/awesome-project.git * [new branch] feature -> feature !!!!!!!!

branching

Page 56: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

git merge <branch>merges changes found in the branch into the current branch

! > git merge feature Updating 80151a6..f22543f Fast-forward index.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) !!!!!!!

branching

Page 57: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

Git NOT for dummies

Page 58: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

config

Page 59: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

config

aliases

Page 60: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

config

aliasesglobal .gitignore

Page 61: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

config

aliasesglobal .gitignorehelp.autocorrect

Page 62: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

assume unchanged

Page 63: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

assume unchanged

ignore changes in file for a moment

! > git update-index --assume-unchanged <file> > git update-index --no-assume-unchanged <file> !!!!!!!!!!

Page 64: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

interactive rebase

Page 65: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

interactive rebase

it’s safe only when you’re sure what are you doing

! > git rebase -i HEAD~10 !!!!!!!!!!!

Page 66: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

cherry-pick

Page 67: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

cherry-pick

applies the changes introduced by some existing commits

Page 68: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

interactive adding, hunks

Page 69: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

interactive adding, hunks

! > git add -i > git add -p !!!!!!!!!!

managing index with wizard, adding part of files (hunks) to staging

Page 70: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

hooks

Page 71: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

hooks

pre-commit, post-commit pre-receive, post-receive…

! > touch .git/hooks/<hook> > edit .git/hooks/<hook> > chmod +x .git/hooks/<hook> ! > npm install -g grunt-githooks > grunt githooks !!!!!

Page 72: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

LOLCOMMITS

Page 73: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

LOLCOMMITS

! > gem install lolcommits > lolcommits —enable > lolcommits —browse !!!!!!!!

Page 74: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

LOLCOMMITS

! > gem install lolcommits > lolcommits —enable > lolcommits —browse !!!!!!!!

Page 75: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

HEAD aka @, ORIG_HEAD

Page 76: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

HEAD aka @, ORIG_HEAD

HEAD is a reference tothe current commit

Page 77: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

HEAD aka @, ORIG_HEAD

HEAD is a reference tothe current commit

@ since Git 1.8.4

Page 78: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

HEAD aka @, ORIG_HEAD

HEAD is a reference tothe current commit

@ since Git 1.8.4

ORIG_HEAD is set before potentially dangerous operations like merge

Page 79: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

reflog

Page 80: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

reflog

will save your ass in case of THE WORST things happen

Page 81: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

reflog

will save your ass in case of THE WORST things happen

Page 82: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

reflog

will save your ass in case of THE WORST things happen

logs changes of HEAD

Page 83: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

reflog

will save your ass in case of THE WORST things happen

logs changes of HEAD

Page 84: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

reflog

will save your ass in case of THE WORST things happen

logs changes of HEAD

git fsck --lost-found in case of tragedy might be helpful too

Page 85: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

bisect

Page 86: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

bisect

find which commit introduced a bug

Page 87: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

clean

Page 88: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

clean

removes untracked files

Page 89: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

clean

removes untracked files

Page 90: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

clean

removes untracked files

with -d also directories

Page 91: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

clean

removes untracked files

with -d also directorieswith -n only shows what would be deleted

Page 92: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

clean

removes untracked files

with -d also directorieswith -n only shows what would be deleted

with -x removes ignored files

Page 93: Internal talk #2 – Git – Arkadiusz Fal, XHTMLized, 2014

thank youquestions?