git introduction
DESCRIPTION
Git learnTRANSCRIPT
![Page 1: Git Introduction](https://reader036.vdocuments.us/reader036/viewer/2022062519/5695cff11a28ab9b0290376b/html5/thumbnails/1.jpg)
1
Git
How to
![Page 2: Git Introduction](https://reader036.vdocuments.us/reader036/viewer/2022062519/5695cff11a28ab9b0290376b/html5/thumbnails/2.jpg)
2
What is Git?
• Git is a version control system
![Page 3: Git Introduction](https://reader036.vdocuments.us/reader036/viewer/2022062519/5695cff11a28ab9b0290376b/html5/thumbnails/3.jpg)
3
Why Git
• To resolve problems in lab exams (accidental deletions)
• Use existing Libraries with ease (Statistics and Computer)
• Prepare undergraduates to face industry challenges
• Efficiently working with research students• Resource sharing
![Page 4: Git Introduction](https://reader036.vdocuments.us/reader036/viewer/2022062519/5695cff11a28ab9b0290376b/html5/thumbnails/4.jpg)
4
Getting Started
![Page 5: Git Introduction](https://reader036.vdocuments.us/reader036/viewer/2022062519/5695cff11a28ab9b0290376b/html5/thumbnails/5.jpg)
5
Getting Started
• Git use snapshot storage
![Page 6: Git Introduction](https://reader036.vdocuments.us/reader036/viewer/2022062519/5695cff11a28ab9b0290376b/html5/thumbnails/6.jpg)
6
Getting Started
• Three stages of Git– The HEAD• last commit snapshot, next parent
– Index• Proposed next commit snapshot
– Working directory• Sandbox
![Page 7: Git Introduction](https://reader036.vdocuments.us/reader036/viewer/2022062519/5695cff11a28ab9b0290376b/html5/thumbnails/7.jpg)
7
Getting Started
• A basic workflow– (Possible init or clone) Init a repo– Edit files– Stage the changes– Review your changes– Commit the changes
![Page 8: Git Introduction](https://reader036.vdocuments.us/reader036/viewer/2022062519/5695cff11a28ab9b0290376b/html5/thumbnails/8.jpg)
8
Getting Git to work
• Downloading– https://git-for-windows.github.io/
• Install– Two interfaces: Command Line and GUI
![Page 9: Git Introduction](https://reader036.vdocuments.us/reader036/viewer/2022062519/5695cff11a28ab9b0290376b/html5/thumbnails/9.jpg)
9
Getting Started
• Init a repository • Git initzachary@zachary-desktop:~/code/gitdemo$ git initInitialized empty Git repository in /home/zachary/code/gitdemo/.git/
zachary@zachary-desktop:~/code/gitdemo$ ls -l .git/total 32drwxr-xr-x 2 zachary zachary 4096 2011-08-28 14:51 branches-rw-r--r-- 1 zachary zachary 92 2011-08-28 14:51 config-rw-r--r-- 1 zachary zachary 73 2011-08-28 14:51 description-rw-r--r-- 1 zachary zachary 23 2011-08-28 14:51 HEADdrwxr-xr-x 2 zachary zachary 4096 2011-08-28 14:51 hooksdrwxr-xr-x 2 zachary zachary 4096 2011-08-28 14:51 infodrwxr-xr-x 4 zachary zachary 4096 2011-08-28 14:51 objectsdrwxr-xr-x 4 zachary zachary 4096 2011-08-28 14:51 refs
![Page 10: Git Introduction](https://reader036.vdocuments.us/reader036/viewer/2022062519/5695cff11a28ab9b0290376b/html5/thumbnails/10.jpg)
10
Getting Started
• A basic workflow– Edit files– Stage the changes– Review your changes– Commit the changes
• Use your favorite editor
![Page 11: Git Introduction](https://reader036.vdocuments.us/reader036/viewer/2022062519/5695cff11a28ab9b0290376b/html5/thumbnails/11.jpg)
11
Getting Started
• A basic workflow– Edit files– Stage the changes– Review your changes– Commit the changes
• Git add filename
zachary@zachary-desktop:~/code/gitdemo$ git status# 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: hello.txt#no changes added to commit (use "git add" and/or "git commit -a")
![Page 12: Git Introduction](https://reader036.vdocuments.us/reader036/viewer/2022062519/5695cff11a28ab9b0290376b/html5/thumbnails/12.jpg)
12
Getting Started
• A basic workflow– Edit files– Stage the changes– Review your changes– Commit the changes
• Git status
zachary@zachary-desktop:~/code/gitdemo$ git add hello.txtzachary@zachary-desktop:~/code/gitdemo$ git status# On branch master# Changes to be committed:# (use "git reset HEAD <file>..." to unstage)## modified: hello.txt#
![Page 13: Git Introduction](https://reader036.vdocuments.us/reader036/viewer/2022062519/5695cff11a28ab9b0290376b/html5/thumbnails/13.jpg)
13
Getting Started
• A basic workflow– Edit files– Stage the changes– Review your changes– Commit the changes
• Git commit
# Please enter the commit message for your changes. Lines starting# with '#' will be ignored, and an empty message aborts the commit.# On branch master# Changes to be committed:# (use "git reset HEAD <file>..." to unstage)## modified: hello.txt#
![Page 14: Git Introduction](https://reader036.vdocuments.us/reader036/viewer/2022062519/5695cff11a28ab9b0290376b/html5/thumbnails/14.jpg)
14
Getting Started
• A basic workflow– Edit files– Stage the changes– Review your changes– Commit the changes
![Page 15: Git Introduction](https://reader036.vdocuments.us/reader036/viewer/2022062519/5695cff11a28ab9b0290376b/html5/thumbnails/15.jpg)
15
Getting Started
• View changes• Git diff– Show the difference
between working directory and staged
• Git diff --cached– Show the difference
between staged and the HEAD
• View history• Git logzachary@zachary-desktop:~/code/gitdemo$ git logcommit efb3aeae66029474e28273536a8f52969d705d04Author: Zachary Ling <[email protected]>Date: Sun Aug 28 15:02:08 2011 +0800
Add second line
commit 453914143eae3fc5a57b9504343e2595365a7357Author: Zachary Ling <[email protected]>Date: Sun Aug 28 14:59:13 2011 +0800
Initial commit
![Page 16: Git Introduction](https://reader036.vdocuments.us/reader036/viewer/2022062519/5695cff11a28ab9b0290376b/html5/thumbnails/16.jpg)
16
Getting Started
• Revert changes (Get back to a previous version)– Git checkout commit_hashzachary@zachary-desktop:~/code/gitdemo$ git logcommit efb3aeae66029474e28273536a8f52969d705d04Author: Zachary Ling <[email protected]>Date: Sun Aug 28 15:02:08 2011 +0800
Add second line
commit 453914143eae3fc5a57b9504343e2595365a7357Author: Zachary Ling <[email protected]>Date: Sun Aug 28 14:59:13 2011 +0800
Initial commitzachary@zachary-desktop:~/code/gitdemo$ git checkout 4539Note: checking out '4539'.
You are in 'detached HEAD' state. You can look around, make experimentalchanges and commit them, and you can discard any commits you make in thisstate without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you maydo so (now or later) by using -b with the checkout command again. Example:
git checkout -b new_branch_name
HEAD is now at 4539141... Initial commit
![Page 17: Git Introduction](https://reader036.vdocuments.us/reader036/viewer/2022062519/5695cff11a28ab9b0290376b/html5/thumbnails/17.jpg)
17
Branching
![Page 18: Git Introduction](https://reader036.vdocuments.us/reader036/viewer/2022062519/5695cff11a28ab9b0290376b/html5/thumbnails/18.jpg)
18
![Page 19: Git Introduction](https://reader036.vdocuments.us/reader036/viewer/2022062519/5695cff11a28ab9b0290376b/html5/thumbnails/19.jpg)
19
![Page 20: Git Introduction](https://reader036.vdocuments.us/reader036/viewer/2022062519/5695cff11a28ab9b0290376b/html5/thumbnails/20.jpg)
20
![Page 21: Git Introduction](https://reader036.vdocuments.us/reader036/viewer/2022062519/5695cff11a28ab9b0290376b/html5/thumbnails/21.jpg)
21
![Page 22: Git Introduction](https://reader036.vdocuments.us/reader036/viewer/2022062519/5695cff11a28ab9b0290376b/html5/thumbnails/22.jpg)
22
![Page 23: Git Introduction](https://reader036.vdocuments.us/reader036/viewer/2022062519/5695cff11a28ab9b0290376b/html5/thumbnails/23.jpg)
23
![Page 24: Git Introduction](https://reader036.vdocuments.us/reader036/viewer/2022062519/5695cff11a28ab9b0290376b/html5/thumbnails/24.jpg)
24
![Page 25: Git Introduction](https://reader036.vdocuments.us/reader036/viewer/2022062519/5695cff11a28ab9b0290376b/html5/thumbnails/25.jpg)
25
![Page 26: Git Introduction](https://reader036.vdocuments.us/reader036/viewer/2022062519/5695cff11a28ab9b0290376b/html5/thumbnails/26.jpg)
26
Merging
• What do we do with this mess?– Merge them
![Page 27: Git Introduction](https://reader036.vdocuments.us/reader036/viewer/2022062519/5695cff11a28ab9b0290376b/html5/thumbnails/27.jpg)
27
Merging
• Steps to merge two branch– Checkout the branch you want to merge onto– Merge the branch you want to merge
![Page 28: Git Introduction](https://reader036.vdocuments.us/reader036/viewer/2022062519/5695cff11a28ab9b0290376b/html5/thumbnails/28.jpg)
28
![Page 29: Git Introduction](https://reader036.vdocuments.us/reader036/viewer/2022062519/5695cff11a28ab9b0290376b/html5/thumbnails/29.jpg)
29
![Page 30: Git Introduction](https://reader036.vdocuments.us/reader036/viewer/2022062519/5695cff11a28ab9b0290376b/html5/thumbnails/30.jpg)
30
![Page 31: Git Introduction](https://reader036.vdocuments.us/reader036/viewer/2022062519/5695cff11a28ab9b0290376b/html5/thumbnails/31.jpg)
31
![Page 32: Git Introduction](https://reader036.vdocuments.us/reader036/viewer/2022062519/5695cff11a28ab9b0290376b/html5/thumbnails/32.jpg)
32
![Page 33: Git Introduction](https://reader036.vdocuments.us/reader036/viewer/2022062519/5695cff11a28ab9b0290376b/html5/thumbnails/33.jpg)
33
![Page 34: Git Introduction](https://reader036.vdocuments.us/reader036/viewer/2022062519/5695cff11a28ab9b0290376b/html5/thumbnails/34.jpg)
34
Working with remote
• Use git clone to replicate repository
• Get changes with – git fetch – git pull (fetches and merges)
• Propagate changes with– git push
• Note: you need to setup pdn proxy in order to work with university network
• Protocols– Local filesystem (file://)– SSH (ssh://)– HTTP (http:// https://)– Git protocol (git://)
– git config --global https.proxy cachex.pdn.ac.lk:3128
– git config --global http.proxy cachex.pdn.ac.lk:3128
![Page 35: Git Introduction](https://reader036.vdocuments.us/reader036/viewer/2022062519/5695cff11a28ab9b0290376b/html5/thumbnails/35.jpg)
35
Working with remote
• One person project– Local repo is enough– No need to bother with
remote
• Small team project– SSH write access for a
few core developers– GIT public read access
![Page 36: Git Introduction](https://reader036.vdocuments.us/reader036/viewer/2022062519/5695cff11a28ab9b0290376b/html5/thumbnails/36.jpg)
36
Working with remote
• Use git remote add to add an remote repository
Git remote add origin [email protected]:FreezingGod/vimcfg.gitzachary@zachary-desktop:~/.vim_runtime$ git remoteorigin
![Page 37: Git Introduction](https://reader036.vdocuments.us/reader036/viewer/2022062519/5695cff11a28ab9b0290376b/html5/thumbnails/37.jpg)
37
Working with remote
• Remote branching– Branch on remote are different from local branch
![Page 38: Git Introduction](https://reader036.vdocuments.us/reader036/viewer/2022062519/5695cff11a28ab9b0290376b/html5/thumbnails/38.jpg)
38
Working with remote
• Remote branching– Branch on remote are
different from local branch
– Git fetch origin to get remote changes
– Git pull origin try to fetch reomte changes and merge it onto current branch
![Page 39: Git Introduction](https://reader036.vdocuments.us/reader036/viewer/2022062519/5695cff11a28ab9b0290376b/html5/thumbnails/39.jpg)
39
Working with remote
• Git push remote_name branch_name– Share your work done on branch_name to remote
remote_name
![Page 40: Git Introduction](https://reader036.vdocuments.us/reader036/viewer/2022062519/5695cff11a28ab9b0290376b/html5/thumbnails/40.jpg)
40
Demonstration
• Refer handout
![Page 41: Git Introduction](https://reader036.vdocuments.us/reader036/viewer/2022062519/5695cff11a28ab9b0290376b/html5/thumbnails/41.jpg)
41
Q&A
• Any questions?