160 likes | 452 Views
Git. What’s G it ?. A B ritish swear A Distributed Version C ontrol S ystem 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. How does G it work?.
E N D
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
How does Git work? commit • Maintains a repository of changes to a folder • The directory can be “saved” (committed) or “opened” (checked out) at any version Working Tree checkout Repository 1 1 2 0ef19fe14ce b a b 997bf04ea5 5f7b5ac909 i i i α Folder icon in public domain. See http://openclipart.org/detail/137155/folder-icon-by-jhnri4-137155
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 Repository Repository push 0ef19fe14ce 997bf04ea5 282bd722f 5f7b5ac909 Other Repository 360acfe22
How do I start with Git? • Install it • Command line • GUI version • Create a new repo with gitinit $> $> ls app bower.jsoncss Gruntfile.js imgjsnode_modulespackage.json test gitinit Initialized 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 add . gitstatus # On branch master # Initial commit # Changes to be committed: # (use "gitrm --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 ... gitstatus # 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) $> $>
How do I commit my files? • Save your changes with git commit git commit [master (root-commit) 645e836] Initial Commit Committer: yule <yule@cs.dal.ca> 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.html create 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.html git add app/index/html git commit -m "Made app awesome" [master 4acef2f] Made app awesome Committer: yule <yule@cs.dal.ca> 1 files changed, 1 insertions(+), 0 deletions(-) $> $> $>
What about removing files? • Can’t just delete the file • Have to use gitrm • Or use git commit -a rmapp/favicon.ico gitstatus # 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") gitrm app/favicon.ico rm 'app/favicon.ico' gitstatus # 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 gitbranch sweet gitbranch * master sweet gitcheckout sweet Switched to branch 'sweet‘ vi Gruntfile.js git commit -a -m "Added ownership" [sweet 43bcbd5] Added ownership Committer: yule <yule@cs.dal.ca> 1 files changed, 2 insertions(+), 0 deletions(-) gitcheckout master Switched to branch 'master' gitmerge sweet Updating 4acef2f..43bcbd5 Fast-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 pull remote: 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/sweet Updating 4acef2f..43bcbd5 Fast-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.json git commit -a -m "Hello" [master 2bc6f5f] Hello Committer: yule <yule@cs.dal.ca> 1 files changed, 1 insertions(+), 1 deletions(-) gitpush 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
Exercise • Install Git • Go to https://github.com/dyule/cscsi3130Exercise • Clone the repo • Make a branch • Make a change to that branch • Commit your change