+ All Categories
Home > Documents > Git Introduction

Git Introduction

Date post: 28-Jan-2016
Category:
Upload: nirosha-n-kumara
View: 214 times
Download: 0 times
Share this document with a friend
Description:
Git learn
Popular Tags:
41
Git How to 1
Transcript
Page 1: Git Introduction

1

Git

How to

Page 2: Git Introduction

2

What is Git?

• Git is a version control system

Page 3: Git Introduction

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

4

Getting Started

Page 5: Git Introduction

5

Getting Started

• Git use snapshot storage

Page 6: Git Introduction

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

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

8

Getting Git to work

• Downloading– https://git-for-windows.github.io/

• Install– Two interfaces: Command Line and GUI

Page 9: Git Introduction

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

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

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

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

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

14

Getting Started

• A basic workflow– Edit files– Stage the changes– Review your changes– Commit the changes

Page 15: Git Introduction

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

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

17

Branching

Page 18: Git Introduction

18

Page 19: Git Introduction

19

Page 20: Git Introduction

20

Page 21: Git Introduction

21

Page 22: Git Introduction

22

Page 23: Git Introduction

23

Page 24: Git Introduction

24

Page 25: Git Introduction

25

Page 26: Git Introduction

26

Merging

• What do we do with this mess?– Merge them

Page 27: Git Introduction

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

28

Page 29: Git Introduction

29

Page 30: Git Introduction

30

Page 31: Git Introduction

31

Page 32: Git Introduction

32

Page 33: Git Introduction

33

Page 34: Git Introduction

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

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

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

37

Working with remote

• Remote branching– Branch on remote are different from local branch

Page 38: Git Introduction

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

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

40

Demonstration

• Refer handout

Page 41: Git Introduction

41

Q&A

• Any questions?


Recommended