a simple introduction to git
DESCRIPTION
TRANSCRIPT
![Page 1: A Simple Introduction to Git](https://reader033.vdocuments.net/reader033/viewer/2022051616/55381b2d550346722e8b4754/html5/thumbnails/1.jpg)
Git A Simple Introduction to
Daniel Tai, 2013
![Page 2: A Simple Introduction to Git](https://reader033.vdocuments.net/reader033/viewer/2022051616/55381b2d550346722e8b4754/html5/thumbnails/2.jpg)
References
1. Lars Vogel, Git Tutorialhttp://www.vogella.com/articles/Git/article.html
2. Atlassian, Git Tutorialhttps://www.atlassian.com/git/
3. Github, Try Git yourselfhttp://try.github.io/
![Page 3: A Simple Introduction to Git](https://reader033.vdocuments.net/reader033/viewer/2022051616/55381b2d550346722e8b4754/html5/thumbnails/3.jpg)
What is version control system?
![Page 4: A Simple Introduction to Git](https://reader033.vdocuments.net/reader033/viewer/2022051616/55381b2d550346722e8b4754/html5/thumbnails/4.jpg)
Distributed version control system
![Page 5: A Simple Introduction to Git](https://reader033.vdocuments.net/reader033/viewer/2022051616/55381b2d550346722e8b4754/html5/thumbnails/5.jpg)
What is Git?
Simply put, Git is a distributed version control system
![Page 6: A Simple Introduction to Git](https://reader033.vdocuments.net/reader033/viewer/2022051616/55381b2d550346722e8b4754/html5/thumbnails/6.jpg)
Local Repository Operations
![Page 7: A Simple Introduction to Git](https://reader033.vdocuments.net/reader033/viewer/2022051616/55381b2d550346722e8b4754/html5/thumbnails/7.jpg)
Git uses "Staging" workflow
![Page 8: A Simple Introduction to Git](https://reader033.vdocuments.net/reader033/viewer/2022051616/55381b2d550346722e8b4754/html5/thumbnails/8.jpg)
Commonly Used Commands● Initialize a repo
○ git init○ git clone
● Add files to staging area○ git add
● Creating a snapshot○ git commit
● Un-track a file○ git rm
● Configuring git○ git config
● Checking status○ git status ○ git diff○ git log
![Page 9: A Simple Introduction to Git](https://reader033.vdocuments.net/reader033/viewer/2022051616/55381b2d550346722e8b4754/html5/thumbnails/9.jpg)
Check here for more detailed stuffs!
https://www.atlassian.com/git/tutorial/git-basics
![Page 10: A Simple Introduction to Git](https://reader033.vdocuments.net/reader033/viewer/2022051616/55381b2d550346722e8b4754/html5/thumbnails/10.jpg)
Before start using git…...
Setup your name and email so others can know who committed changes:
$ git config --global user.name "<name>"
$ git config --global user.email "<email>"
![Page 11: A Simple Introduction to Git](https://reader033.vdocuments.net/reader033/viewer/2022051616/55381b2d550346722e8b4754/html5/thumbnails/11.jpg)
Initializing a repo
● git init○ Create a repo locally
● git clone <repo>○ Clone another repo○ More on this later
![Page 12: A Simple Introduction to Git](https://reader033.vdocuments.net/reader033/viewer/2022051616/55381b2d550346722e8b4754/html5/thumbnails/12.jpg)
Staging files and Reverting changes
● git add <file>○ Add <file> to staging area
● git reset <file>○ Remove <file> from staging area○ See later slides for more about git reset
● Don’t get confused with: git rm <file>○ Untrack and delete <file>
![Page 13: A Simple Introduction to Git](https://reader033.vdocuments.net/reader033/viewer/2022051616/55381b2d550346722e8b4754/html5/thumbnails/13.jpg)
Creating a snapshot
● git commit -m '<comment>'○ Create a snapshot of all files in staging area○ Always add comments, so you and others can see
what you’ve been doing
![Page 14: A Simple Introduction to Git](https://reader033.vdocuments.net/reader033/viewer/2022051616/55381b2d550346722e8b4754/html5/thumbnails/14.jpg)
Checking Status
● git status○ Check for status: staged files and new files
● git diff○ Check for changes in files
● git log○ Check commit log
![Page 16: A Simple Introduction to Git](https://reader033.vdocuments.net/reader033/viewer/2022051616/55381b2d550346722e8b4754/html5/thumbnails/16.jpg)
Commonly Used Commands, cont.● Viewing previous commits
○ git checkout● Undo a commit
○ git revert● Unstage or revert files
○ git reset● Delete all un-tracked files
○ git clean
![Page 17: A Simple Introduction to Git](https://reader033.vdocuments.net/reader033/viewer/2022051616/55381b2d550346722e8b4754/html5/thumbnails/17.jpg)
Viewing previous commits
● git checkout <commit>○ Checkout <commit>. You will be detached from
master branch.● git checkout <commit> <file>
○ Checkout <file> in <commit> and put it into stage area
○ Use this function to revive old version of file into new commits
![Page 18: A Simple Introduction to Git](https://reader033.vdocuments.net/reader033/viewer/2022051616/55381b2d550346722e8b4754/html5/thumbnails/18.jpg)
Reverting old commits
● git revert <commit>○ Revert to <commit> and make it as a new commit
![Page 19: A Simple Introduction to Git](https://reader033.vdocuments.net/reader033/viewer/2022051616/55381b2d550346722e8b4754/html5/thumbnails/19.jpg)
Resetting commits
● git reset <file>○ Remove <file> from staging area○ Does not change file content
● git reset ○ Remove all files from staging area○ Does not change file content
● git reset has some other dangerous functions, see here. Never use them if you don’t fully understand it.
![Page 20: A Simple Introduction to Git](https://reader033.vdocuments.net/reader033/viewer/2022051616/55381b2d550346722e8b4754/html5/thumbnails/20.jpg)
Working with Remote Repositories
![Page 21: A Simple Introduction to Git](https://reader033.vdocuments.net/reader033/viewer/2022051616/55381b2d550346722e8b4754/html5/thumbnails/21.jpg)
Commands related to remote repos● Assigning remote repository
○ git remote add <url>● Upload local commits
○ git push● Download remote commits
○ git pull
![Page 22: A Simple Introduction to Git](https://reader033.vdocuments.net/reader033/viewer/2022051616/55381b2d550346722e8b4754/html5/thumbnails/22.jpg)
Working with Github
1. Apply a Github account here(Optionally, you can upgrade to education account here)
2. Make sure that you’ve setup your name and email (see this slide)
3. Follow the instructions here
![Page 23: A Simple Introduction to Git](https://reader033.vdocuments.net/reader033/viewer/2022051616/55381b2d550346722e8b4754/html5/thumbnails/23.jpg)
Connect with remote repo
● Case 1: You’ve started a local repo. You want to push to remote repo○ git remote add origin <url>
■ The <url> can be obtained on Github page○ git push -u origin master
● Case 2: You are cloning other’s remote repo○ git clone <url>
![Page 24: A Simple Introduction to Git](https://reader033.vdocuments.net/reader033/viewer/2022051616/55381b2d550346722e8b4754/html5/thumbnails/24.jpg)
Synchronizing changes
● git pull○ Pull (download) remote commits and merge them
into working directory○ Merging is usually done automatically
● git push○ Push (upload) your local commits
![Page 25: A Simple Introduction to Git](https://reader033.vdocuments.net/reader033/viewer/2022051616/55381b2d550346722e8b4754/html5/thumbnails/25.jpg)
Hands on Time!
Back to http://try.github.io and finish to challenge 17
Open a repo on Github and try playing around your self
![Page 26: A Simple Introduction to Git](https://reader033.vdocuments.net/reader033/viewer/2022051616/55381b2d550346722e8b4754/html5/thumbnails/26.jpg)
Branch and other stuff…...
Check out the references for more!