1 / 30

Introduction to Git

Introduction to Git. Chu-Cheng Hsieh chucheng @ ucla.edu. What is git. a distributed revision control and source code management (SCM) system What the hell?. You want a CTRL-Z for your documents. Create a readme file in cs144/ mkdir cs144 cd cs144 echo “This is a readme” >> readme.txt.

lindley
Download Presentation

Introduction to Git

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Git Chu-Cheng Hsieh chucheng@ucla.edu

  2. What is git • a distributed revision control and source code management (SCM) system • What the hell?

  3. You want a CTRL-Z for your documents • Create a readme file in cs144/mkdir cs144cd cs144echo “This is a readme” >> readme.txt

  4. git in English • Track your changes by making a snapshot (hashcode) • “gitinit” • Create a “.git” folder in your folder to track the changes ~/github/cs144$ gitinit Initialized empty Git repository in /Users/chucheng/github/cs144/.git/

  5. Tell git to track files (put flags on them) • add a file • git add <filename> • add a dir and everything inside this dir • git add <dir> • add everything • git add . ~/github/cs144$ git add readme.txt

  6. Compute a hash and make a snapshot • a8a9469 is the “hash” of the snapshot ~/github/cs144$ git commit -m "Create a readme file" [master (root-commit) a8a9469] Create a readme file 1 file changed, 1 insertion(+) create mode 100644 readme.txt ~/github/cs144$ git log commit a8a946980ffaa1d0fa1c7dfe35f1f18c3fac267c Author: Chu-Cheng Hsieh <chucheng@ucla.edu> Date: Thu Oct 11 21:32:21 2012 -0700 Create a readme file

  7. gitx (any gitgui tool)

  8. Now you make a mistake • To see a difference ~/github/cs144$ git diff readme.txt diff --git a/readme.txt b/readme.txt index 24308cb..c920514 100644 --- a/readme.txt +++ b/readme.txt @@ -1 +1 @@ -This is a readme +Oh… I forget submit Project 1 • To rollback to last commit git checkout readme.txt

  9. What if you already make a commit? • Suppose we make a mistake… • To rollback to any point $ git commit -am "Second commit" [master d5b61af] Second commit 1 file changed, 1 insertion(+), 1 deletion(-) $ gitreset --hard a8a946 HEAD is now at a8a9469 Create a readme file $ cat readme.txt This is a readme

  10. “master branch” • Remembering “sha” is stupid… • Create a “pointer” with a name • default “pointer” is master $ gitbranch * master

  11. If you need another pointer for trying something … $ git checkout -b feature-kill-virus Switched to a new branch 'feature-kill-virus’ $ git branch * feature-kill-virus master

  12. Working in a branch • git checkout <branch> $ git commit -am "kill all virus in a branch” [feature-kill-virus 1a2970b] kill all virus in a branch 1 file changed, 2 insertions(+), 2 deletions(-)

  13. branch is a pointer • Every sha only “know” which sha is its predecessor

  14. Branch • Help you know… • where you “were” • give you a convenient to try something but do not have to worry the consequence • Or if later you are happy with things you “try”… you can merge

  15. git merge • git do “smart merge” $ git branch * feature-kill-virus master$ git checkout master$ git branch feature-kill-virus * master$ gitmerge feature-kill-virus Merge made by the 'recursive' strategy. readme.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)

  16. Some popular branch command • Create a new branch from current branch • git checkout –b <new_branch> • Switch between branch • git checkout <target_branch> • example: git checkout master • To see all branch • git branch • To delete a branch • git branch –d <name>

  17. In a word … • Git is a (super) smart ctrl-z • Every time you make a “commit”  taking a snapshot • A snapshot is represented by “sha” • You can roll back to any snapshot (time machine) • You can tell a difference….between different versions • You can create a branch to “try something” • Once you are done you can then “merge back”

  18. What if “.git” can be automatically sync between two persons. • You can see what changes your partner made (and at what time) • You can control-z to any point, compare (diff) between your work and his/her work • But how?

  19. Github? • An online repository • keep a copy of your .git • allow others to “download” your git • github.com/edu github upload download Chucheng Young

  20. Create a repository

  21. Use their interface

  22. You need tell where to sync This is just an “alias” $ git remote add origin https://github.com/chucheng/cs144.git $ git remote -v origin https://github.com/chucheng/cs144.git (fetch) origin https://github.com/chucheng/cs144.git (push) github Chucheng

  23. upload (push)*don’t forget “-u” for the first push $ gitpush -u Username for 'https://github.com': chucheng Password for 'https://chucheng@github.com': To https://github.com/chucheng/cs144.git * [new branch] master -> master github push Chucheng

  24. download (pull)* If there is a conflict, you will see a “diff” results $ git pull Already up-to-date. github pull Chucheng

  25. How to release the power of branch Ref: http://nvie.com/posts/a-successful-git-branching-model/

  26. Develop branch • Have a develop branch, keep your master “clean”

  27. Feature branches • When you want to try some thing (new feature… which might take a while) • create a branch • merge back to develop once you are done • Snapshot in master branch • runnable • Snapshot in develop • able to be compiled without error

  28. Hotfix – Emergency request • What if you need fix a bug for your partner but you are in the middle of doing something • Tag is just a permanent convenient alias for a hash • Using “branch” + “merge” to support multi-tasking

  29. @nvie

  30. Some reference • Tutorial • http://git-scm.com/book • http://www-cs-students.stanford.edu/~blynn/gitmagic/ • Sites: • http://jonas.nitro.dk/git/quick-reference.html • http://nvie.com/posts/a-successful-git-branching-model/

More Related