Download presentation
Presentation is loading. Please wait.
1
Backing up a machine with git
St. Louis Unix User's Group 13 April 2016 Lee Lammert Omnitec Corporation SLUUG 13 April 2016
2
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
3
Git is distributed version control system focused on speed, effectivity and real-world usability on large projects. - git-scm.com SLUUG 13 April 2016
4
git is, .. Directory content management system
Tree history storage system A toolkit Stupid content tracker The “plumbing”! SLUUG 13 April 2016
5
Basic source control system
SLUUG 13 April 2016
6
but why git? SLUUG 13 April 2016
7
let’s git started SLUUG 13 April 2016
8
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
9
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
10
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
11
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 bob create mode lee create mode steve $ gs On branch master nothing to commit, working directory clean SLUUG 13 April 2016
12
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 bob create mode lee create mode steve $ gs On branch master nothing to commit, working directory clean SLUUG 13 April 2016
13
Need to ignore some files!
$ cat .gitignore *~ $ git commit .gitignore -m "Added .gitignore" [master ae5e55b] Added .gitignore 1 file changed, 1 insertion(+) create mode 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
14
Look at changes git diff alias gd='git diff' $ gd lee
diff --git a/lee b/lee index e69de29..3c73ecc --- a/lee +++ b/lee -0,0 +1 +This is a changed file! SLUUG 13 April 2016
15
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
16
Check the history $ git log
commit ae5e55bce726b35f62ae945a2a52705f99ecb5cf Author: L. V. Lammert Date: Wed Apr 13 15:33: Added .gitignore commit a adbae38abb64ffcc15ba cae1 Date: Wed Apr 13 15:28: Initial Version SLUUG 13 April 2016
17
Configuring the repo $ git config --global user.name "L V Lammert"
$ git config --global user. SLUUG 13 April 2016
18
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
19
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
20
Create a remote copy Setup a keypair for access, and test
Init the repo there $ ssh apollo Last login: Wed Apr 13 12:28: from marvel.omnitec.net OpenBSD 4.8 (GENERIC) #136: Mon Aug 16 09:06:23 MDT 2010 (-bash) $ mkdir SLUUG_Repo $ git init --bare Initialized empty Git repository in /u/lvl/ SLUUG 13 April 2016
21
Connect your repo Add a remote to the local repo
$ git remote add SLUUG apollo:SLUUG_repo $ git remote SLUUG SLUUG 13 April 2016
22
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
23
more git uses Undoing changes Checkout a specific version
$ git checkout lee $ git checkout d20c7a295965f798109f9d4af0fbeedd8 <file name> SLUUG 13 April 2016
24
developing parallel with branching
25
create a branch $ git checkout -b bugfix
Switched to a new branch “bugfix”
26
switching branches $ git status $ git checkout master
# On branch bugfix nothing to commit (working directory clean) $ git checkout master Switched to branch “master”
27
collaborating with git
28
public repos = free private repos = cheap
29
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), KiB, done. Resolving deltas: 100% (54/54), done. $ cd hello-world
30
pull changes (and pull often)
$ git pull origin master
31
add changes to master $ git checkout master $ git merge bugfix
32
push changes $ git push origin master
33
configure & customize git
34
add pretty colors $ git config --global color.diff auto
$ git config --global color.status auto $ git config --global color.branch auto
35
git tools
36
gitk
37
GitX
38
TortoiseGit
39
git resources
40
Pro Git (book)
41
Pragmatic Version Control Using Git (book)
42
Git Community Book
43
Git Cheat Sheet
44
what to remember commit often pull often
use checkout and reset with caution create your own repository anywhere
45
fin
46
linkedin.com/in/erincarter
illustrations by Simon Oxley of idokungfood.com theme inspired by Scott Chacon’s git-scm.com
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.