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

Post on 25-Jan-2015

59 Views

Category:

Engineering

2 Downloads

Preview:

Click to see full reader

DESCRIPTION

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

TRANSCRIPT

The Master of VCS !

Internal Talk #2Arkadiusz Fal

What is Git

revision control

tracking changes

revision control

tracking changescollaboration

revision control

tracking changescollaboration

nothing will ever be gone

revision control

tracking changescollaboration

nothing will ever be gonereverting changes

revision control

tracking changescollaboration

nothing will ever be gonereverting changes

sharing code

revision control

version control systems

stand-alone applications built to manage versioning

!

!

version control systems

stand-alone applications built to manage versioning

!

!

version control systems

stand-alone applications built to manage versioning

!

!

version control systems

stand-alone applications built to manage versioning

!

!

version control systems

…but Git is better!

smaller, faster, feature-loaded !

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

Git basics

common tasks

git initcreates a new, empty Git repository

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

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) !!

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 !!

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 !!!!

common tasks

git log shows commit history

! > git log commit 1a9925e4797490b874f6430b264164004356f8e6 Author: Arkadiusz Fal <arek@arekf.net> Date: Sun Mar 30 15:50:54 2014 +0200 ! Initial commit !!!!!!

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; !

common tasks

common tasks

git rm <file>removes file from index

common tasks

git rm <file>removes file from index

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

common tasks

git rm <file>removes file from index

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

Coworking with Git

Git remotes

Git remotes

servers in the Internet that store and let manage repositories

Git remotes

servers in the Internet that store and let manage repositories

Git remotes

servers in the Internet that store and let manage repositories

Git remotes

servers in the Internet that store and let manage repositories

Git remotes

servers in the Internet that store and let manage repositories

Git remotes

servers in the Internet that store and let manage repositories

…and many more

git clonecreates a copy of existing repository

! > git clone git@github.com: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

collaboration with Git

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

! > git remote add origin git@github.com:arekf/awesome-project.git !!!!!!!!!!!

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 git@github.com:arekf/awesome-project.git * [new branch] master -> master !!!!

collaboration with Git

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

collaboration with Git

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

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

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

Branching

branching

Branch is a independent line of development. Has independent working

directory and history.

branching

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

branching

branching

C1

branching

C1

master

branching

C1

master

C2

branching

C1

master

C2

branching

C1

master

C2

feature

branching

C1

master

C2

feature

C3

branching

C1

master

C2

feature

C3

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

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

branching

git checkout <name>switches to other branch

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

branching

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

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

branching

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

Git NOT for dummies

config

config

aliases

config

aliasesglobal .gitignore

config

aliasesglobal .gitignorehelp.autocorrect

assume unchanged

assume unchanged

ignore changes in file for a moment

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

interactive rebase

interactive rebase

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

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

cherry-pick

cherry-pick

applies the changes introduced by some existing commits

interactive adding, hunks

interactive adding, hunks

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

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

hooks

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 !!!!!

LOLCOMMITS

LOLCOMMITS

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

LOLCOMMITS

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

HEAD aka @, ORIG_HEAD

HEAD aka @, ORIG_HEAD

HEAD is a reference tothe current commit

HEAD aka @, ORIG_HEAD

HEAD is a reference tothe current commit

@ since Git 1.8.4

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

reflog

reflog

will save your ass in case of THE WORST things happen

reflog

will save your ass in case of THE WORST things happen

reflog

will save your ass in case of THE WORST things happen

logs changes of HEAD

reflog

will save your ass in case of THE WORST things happen

logs changes of HEAD

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

bisect

bisect

find which commit introduced a bug

clean

clean

removes untracked files

clean

removes untracked files

clean

removes untracked files

with -d also directories

clean

removes untracked files

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

clean

removes untracked files

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

with -x removes ignored files

thank youquestions?

top related