Backing up a machine with git St. Louis Unix User's Group 13 April 2016 Lee Lammert Omnitec Corporation SLUUG 13 April 2016
so, what’s git? A distributed revision control system with an emphasis on: Speed Data integrity Support for distributed, non-linear workflows Initially designed and developed in 2005 by Linus Torvalds and the Linux kernel developers SLUUG 13 April 2016
Git is distributed version control system focused on speed, effectivity and real-world usability on large projects. - git-scm.com SLUUG 13 April 2016
git is, .. Directory content management system Tree history storage system A toolkit Stupid content tracker The “plumbing”! SLUUG 13 April 2016
Basic source control system SLUUG 13 April 2016
but why git? SLUUG 13 April 2016
let’s git started SLUUG 13 April 2016
Create a repository $ cd (project-directory) $ git init Initialized empty Git repository in .git/ $ gs On branch master Initial commit nothing to commit (create/copy files and use "git add" to track) SLUUG 13 April 2016
What was that? Being old-school cli, I am a firm believer that the fewer characters the better: alias gs='git status' alias gd='git diff' SLUUG 13 April 2016
Add some files $ touch lee $ touch bob $ touch steve $ gs On branch master Initial commit Untracked files: (use "git add <file>..." to include in what will be committed) bob lee steve nothing added to commit but untracked files present (use "git add" to track) $ git add * SLUUG 13 April 2016
Add them to the repo $ git commit -m "Initial Version" [master (root-commit) a037529] Initial Version 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 bob create mode 100644 lee create mode 100644 steve $ gs On branch master nothing to commit, working directory clean SLUUG 13 April 2016
Change something $ gs 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: lee Untracked files: (use "git add <file>..." to include in what will be committed) lee~ no changes added to commit (use "git add" and/or "git commit -a") $ git commit -m "Initial Version" [master (root-commit) a037529] Initial Version 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 bob create mode 100644 lee create mode 100644 steve $ gs On branch master nothing to commit, working directory clean SLUUG 13 April 2016
Need to ignore some files! $ cat .gitignore *~ $ git commit .gitignore -m "Added .gitignore" [master ae5e55b] Added .gitignore 1 file changed, 1 insertion(+) create mode 100644 .gitignore $ gs 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: lee no changes added to commit (use "git add" and/or "git commit -a") SLUUG 13 April 2016
Look at changes git diff alias gd='git diff' $ gd lee diff --git a/lee b/lee index e69de29..3c73ecc 100644 --- a/lee +++ b/lee @@ -0,0 +1 @@ +This is a changed file! SLUUG 13 April 2016
Two ways to add files Adding a individual file Adding a multiple files $ git add README Adding a multiple files $ git add . SLUUG 13 April 2016
Check the history $ git log commit ae5e55bce726b35f62ae945a2a52705f99ecb5cf Author: L. V. Lammert <lvl@omnitec.net> Date: Wed Apr 13 15:33:51 2016 -0500 Added .gitignore commit a0375291adbae38abb64ffcc15ba67297666cae1 Date: Wed Apr 13 15:28:28 2016 -0500 Initial Version SLUUG 13 April 2016
Configuring the repo $ git config --global user.name "L V Lammert" $ git config --global user.email "lvl@omnitec.net" SLUUG 13 April 2016
So, .. what about this backup thing? git operates in the current directory Unlimited versions, changes, tracking, tags, collaboration uses the repo BUT, a repo is not saved anywhere else! SLUUG 13 April 2016
Local .git directory $ ls -al .git total 24 drwxrwxr-x 8 lvl users 155 Apr 13 15:34 ./ drwxrwxr-x 3 lvl users 77 Apr 13 15:32 ../ drwxrwxr-x 2 lvl users 6 Apr 13 15:19 branches/ -rw-rw-r-- 1 lvl users 17 Apr 13 15:33 COMMIT_EDITMSG -rwxrw-r-- 1 lvl users 92 Apr 13 15:19 config* -rw-rw-r-- 1 lvl users 73 Apr 13 15:19 description -rw-rw-r-- 1 lvl users 23 Apr 13 15:19 HEAD drwxrwxr-x 2 lvl users 4096 Apr 13 15:19 hooks/ -rw-rw-r-- 1 lvl users 328 Apr 13 15:33 index drwxrwxr-x 2 lvl users 20 Apr 13 15:19 info/ drwxrwxr-x 3 lvl users 28 Apr 13 15:28 logs/ drwxrwxr-x 10 lvl users 82 Apr 13 15:33 objects/ drwxrwxr-x 4 lvl users 29 Apr 13 15:19 refs/ SLUUG 13 April 2016
Create a remote copy Setup a keypair for access, and test Init the repo there $ ssh apollo Last login: Wed Apr 13 12:28:39 2016 from marvel.omnitec.net OpenBSD 4.8 (GENERIC) #136: Mon Aug 16 09:06:23 MDT 2010 lvl@Apollo:~ (-bash) $ mkdir SLUUG_Repo $ git init --bare Initialized empty Git repository in /u/lvl/ SLUUG 13 April 2016
Connect your repo Add a remote to the local repo $ git remote add SLUUG apollo:SLUUG_repo $ git remote SLUUG SLUUG 13 April 2016
push local to remote $ git push SLUUG master Counting objects: 6, done. Delta compression using up to 6 threads. Compressing objects: 100% (4/4), done. Writing objects: 100% (6/6), 483 bytes | 0 bytes/s, done. Total 6 (delta 0), reused 0 (delta 0) To apollo:SLUUG_Repo * [new branch] master -> master $ git push SLUUG master Counting objects: 6, done. Delta compression using up to 6 threads. Compressing objects: 100% (4/4), done. Writing objects: 100% (6/6), 483 bytes | 0 bytes/s, done. Total 6 (delta 0), reused 0 (delta 0) To apollo:SLUUG_Repo * [new branch] master -> master SLUUG 13 April 2016
more git uses Undoing changes Checkout a specific version $ git checkout lee $ git checkout 3607253d20c7a295965f798109f9d4af0fbeedd8 <file name> SLUUG 13 April 2016
developing parallel with branching
create a branch $ git checkout -b bugfix Switched to a new branch “bugfix”
switching branches $ git status $ git checkout master # On branch bugfix nothing to commit (working directory clean) $ git checkout master Switched to branch “master”
collaborating with git
public repos = free private repos = cheap
clone a hosted repository $ git clone git://github.com/git/hello-world.git Initialized empty Git repository in /Users/me/Projects/hello-world/.git/ remote: Counting objects: 158, done. remote: Compressing objects: 100% (79/79), done. remote: Total 158 (delta 54), reused 157 (delta 54) Receiving objects: 100% (158/158), 15.62 KiB, done. Resolving deltas: 100% (54/54), done. $ cd hello-world
pull changes (and pull often) $ git pull origin master
add changes to master $ git checkout master $ git merge bugfix
push changes $ git push origin master
configure & customize git
add pretty colors $ git config --global color.diff auto $ git config --global color.status auto $ git config --global color.branch auto
git tools
gitk
GitX
TortoiseGit
git resources
Pro Git (book)
Pragmatic Version Control Using Git (book)
Git Community Book
Git Cheat Sheet
what to remember commit often pull often use checkout and reset with caution create your own repository anywhere
fin
linkedin.com/in/erincarter illustrations by Simon Oxley of idokungfood.com theme inspired by Scott Chacon’s git-scm.com