git. what’s git? a british swear a distributed version control system developed in 2005 by linus...
TRANSCRIPT
Git
What’s Git?•A British swear
•A Distributed Version Control System
•Developed in 2005 by Linus Torvalds for use on the Linux Kernel
Git Logo by Jason Long used under Creative Commons Attribution License. See http://git-scm.com/downloads/logos
2
b
i
α
1
b
i
1
a
i
How does Git work?•Maintains a repository of changes to a folder
•The directory can be “saved” (committed) or “opened” (checked out) at any version
Working Tree
Repository0ef19fe14ce
997bf04ea5
5f7b5ac909
Folder icon in public domain. See http://openclipart.org/detail/137155/folder-icon-by-jhnri4-137155
commit
checkout
But wait, there’s more!•You can branch your tree, so you can work on multiple features at once
•You can share your changes with other developers
Repository0ef19fe14ce
997bf04ea5
5f7b5ac909
282bd722f
360acfe22
Repository
Other Repository
push
How do I start with Git?• Install it
◦ Command line◦ GUI version
•Create a new repo with git init
lsapp bower.json css Gruntfile.js img js node_modules package.json testgit initInitialized empty Git repository in ~/gitdemo/.git/
$>
$>
How do I add files to Git?•Files and folders are not tracked by default
•Files must be staged before committing with git add
git status# On branch master# Initial commit# Untracked files:# (use "git add <file>..." to include in what will be committed)# Gruntfile.js# app/# bower.json# img/# package.json# test/nothing added to commit but untracked files present (use "git add" to track)
$>$>$>
git add .git status# On branch master# Initial commit# Changes to be committed:# (use "git rm --cached <file>..." to unstage)# new file: .bowerrc# new file: .editorconfig# new file: Gruntfile.js# new file: app/.htaccess# new file: app/404.html# new file: app/favicon.ico# new file: app/index.html...
How do I commit my files?•Save your changes with git commit
$> git commit[master (root-commit) 645e836] Initial Commit Committer: yule <[email protected]>19 files changed, 1564 insertions(+), 0 deletions(-) create mode 100644 .bowerrc create mode 100644 .editorconfig create mode 100644 .gitignore create mode 100644 .jshintrc create mode 100644 Gruntfile.js create mode 100644 app/.htaccess create mode 100644 app/404.htmlcreate mode 100644 app/index.html ...
How do I update and commit?•Edit your files
•Stage your changes
•Commit them
•Combine both using git commit -a
$>$>$>
vi app/index.htmlgit add app/index/htmlgit commit -m "Made app awesome"[master 4acef2f] Made app awesome Committer: yule <[email protected]>
1 files changed, 1 insertions(+), 0 deletions(-)
What about removing files?•Can’t just delete the file
•Have to use git rm
•Or use git commit -a
$>$>
rm app/favicon.icogit status# On branch master# Changed but not updated:# (use "git add/rm <file>..." to update what will be committed)# (use "git checkout -- <file>..." to discard changes in working directory)## deleted: app/favicon.ico#no changes added to commit (use "git add" and/or "git commit -a")
$>
$>
git rm app/favicon.icorm 'app/favicon.ico'git status# On branch master# Changes to be committed:# (use "git reset HEAD <file>..." to unstage)## deleted: app/favicon.ico
How do branches work?•Create using git branch
•Change working tree with git checkout
•Combine with git merge
$>$>
$>
$>$>
git branch sweetgit branch* master sweetgit checkout sweetSwitched to branch 'sweet‘vi Gruntfile.jsgit commit -a -m "Added ownership"[sweet 43bcbd5] Added ownership Committer: yule <[email protected]> 1 files changed, 2 insertions(+), 0 deletions(-)
$>
$>
git checkout masterSwitched to branch 'master'git merge sweetUpdating 4acef2f..43bcbd5Fast-forward Gruntfile.js | 2 ++1 file changed, 2 insertions(+), 0 deletions(-)
How can I share my changes?
•Update from a remote repo using git pull
•Send changes using git push
git pullremote: Counting objects: 7, done.remote: Compressing objects: 100% (4/4), done.remote: Total 4 (delta 3), reused 0 (delta 0)Unpacking objects: 100% (4/4), done.From remote/gitdemo 4acef2f..43bcbd5 master -> origin/master 4acef2f..43bcbd5 sweet -> origin/sweetUpdating 4acef2f..43bcbd5Fast-forward Gruntfile.js | 2 ++ app/favicon.ico | Bin 4286 -> 0 bytes 2 files changed, 2 insertions(+), 0 deletions(-) delete mode 100644 app/favicon.ico
$> vi package.jsongit commit -a -m "Hello"[master 2bc6f5f] Hello Committer: yule <[email protected]> 1 files changed, 1 insertions(+), 1 deletions(-)git push Counting objects: 5, done.Compressing objects: 100% (3/3), done.Writing objects: 100% (3/3), 309 bytes, done.Total 3 (delta 2), reused 0 (delta 0)Unpacking objects: 100% (3/3), done.To remote 43bcbd5..2bc6f5f master -> master
$>$>
$>
Other points•You can create a file called .gitignore that lists file extensions git won’t include
•To create a local copy of a repository, use git clone
Exercise1. Install Git
2. Go to https://github.com/dyule/cscsi3130Exercise
3. Clone the repo
4. Make a branch
5. Make a change to that branch
6. Commit your change