• No results found

Git Real Slides

N/A
N/A
Protected

Academic year: 2021

Share "Git Real Slides"

Copied!
60
0
0

Loading.... (view fulltext now)

Full text

(1)
(2)

L E V E L 1 L E V E L 1

(3)

L E V E L 1 L E V E L 1

(4)

S A M E O L D S T O R Y

S A M E O L D S T O R Y

 C

 C

 o

 o

 l

 l

 l

 l

a

a

 b

 b

 o

 o

 r

 r

a

a

 t

 t

 i

 i

 o

 o

 n

 n

 I

(5)

V E R S I O N C O N T R O L S Y S T E M S

Mer  gi n g

(6)

R E P O S I T O R Y L O C A T I O N S

(7)

D I S T R I B U T E D V E R S I O N C O N T R O L S Y S T E M

Git is a

(8)

O R I G I N S

Linux Kernel project.

• Meant to be distributed, fast and more natural.

• Capable of handling large projects.

(9)

W O R K I N G W I T H G I T

Command line interface

• O

!

cial Git Site —

st ar t her e

http://git-scm.com/

• Many GUI tools available

(10)

G I T H E L P

$ git help

usage: git [--version] [--exec-path[=<path>]] [--html-path] [-p|--paginate|--no-pager] [--no-replace-objects] [--bare] [--git-dir=<path>] [--work-tree=<path>] [-c name=value] [--help]

<command> [<args>]

The most commonly used git commands are:

add Add file contents to the index

bisect Find by binary search the change that introduced a bug ...

(11)

 GIT-CONFIG(1) Git Manual GIT-CONFIG(1)

NAME

git-config - Get and set repository or global options SYNOPSIS

git config [<file-option>] [type] [-z|--null] name [value [value_regex]] git config [<file-option>] [type] --add name value

...

$ git help config

G I T H E L P

(12)

S E T T I N G U P G I T

Pretty command line colors

Who gets credit for changes

What email you use

$ git config --global user.name "Gregg Pollack"

$ git config --global user.email [email protected] $ git config --global color.ui true

(13)

S T A R T I N G A R E P O

 git metadata is stored here

$ mkdir store $ cd store $ git init

(14)

G I T W O R K F L O W

 Jane creates README.txt

"

le

Add

"

le to staging area

Commit changes

Getting ready to take a picture

A snapshot of those on the stage

Starts as untracked 

(15)

Commit changes

Commit changes

G I T W O R K F L O W

G I T W O R K F L O W

 Jane creates README.txt

 Jane creates README.txt

"

"

le

le

Add

Add

"

"

le to staging area

le to staging area

 Jane modi

 Jane modi

"

"

es README.txt

es README.txt

"

"

le & adds LICENSE

le & adds LICENSE

Add both

Add both

"

"

les to staging area

les to staging area

Commit changes

(16)

# On branch master # On branch master # # # Initial commit # Initial commit # # # Untracked files: # Untracked files: #

# (use (use "git "git add add <file>..." <file>..." to to include include in in what what will will be be committed)committed)

#

#

#

# README.txtREADME.txt

nothing added to commit but untracked files present (use "git add" to track)

nothing added to commit but untracked files present (use "git add" to track)

Our newly created file

Our newly created file

 Jane creates README.txt

 Jane creates README.txt

"

"

le

le

$

(17)

Our staged file

Our staged file

$

$ git add README.txt git add README.txt

 git status  git status $ $ # On branch master # On branch master # # # Initial commit # Initial commit # # # Changes to be committed: # Changes to be committed: #

# (use (use "git "git rm rm --cached --cached <file>..." <file>..." to to unstage)unstage)

#

#

#

# new new file: file: README.txtREADME.txt

#

#

Add

(18)

$ git commit -m "Create a README." [master abe28da] Create a README.

 1 files changed, 1 insertions(+), 0 deletions(-)  create mode 100644 README.txt

Commit changes

$ git status

# On branch master

nothing to commit (working directory clean)

No new or modified files since last commit

Commit message

what work was done?

timeline

(19)

# On branch master

# Changed but not updated: # # modified: README.txt # # Untracked files: # # LICENSE

no changes added to commit $ git status

 Jane modi

"

es README.txt

"

le & adds LICENSE

(20)

$ git add README.txt LICENSE

$ git add --all

Add both

"

les to staging area

Adds all new or modified files

OR

# On branch master

# Changes to be committed: #

# new file: LICENSE # modified: README.txt #

$ git status

(21)

$ git commit -m "Add LICENSE and finish README." [master 1b0019c] Add LICENSE and finish README.  2 files changed, 21 insertions(+), 0 deletions(-)  create mode 100644 LICENSE

(22)

G I T T I M E L I N E H I S T O R Y

commit 1b0019c37e3f3724fb2e9035e6bab4d7d87bf455  Author: Gregg Pollack <[email protected]>

Date: Thu Jul 5 22:31:27 2012 -0400 Add LICENSE and finish README.

commit 5acaf86b04aaf9cbbb8ebb9042a20a46d0b9ce76  Author: Gregg Pollack <[email protected]>

Date: Thu Jul 5 22:00:46 2012 -0400 Create a README.

(23)

D I F F E R E N T W A Y S T O A D D

$ git add <list of files> $ git add --all

$ git add *.txt

Add all txt files in current directory

$ git add docs/*.txt

Add all txt files in docs directory

$ git add docs/

Add all files in docs directory

$ git add "*.txt"

Add all txt files in the whole project

Add the list of files

Add all files

(24)
(25)
(26)

S T A G I N G & R E M O T E S

(27)

G I T D I F F

LICENSE

 Copyright (c) 2012 Envy Labs LLC ...

Permission is hereby granted, free of charge, to any person  obtaining a copy

LICENSE

 Copyright (c) 2012 Code School LLC ...

Permission is hereby granted, free  of charge, to any person obtaining  a copy

 diff --git a/LICENSE b/LICENSE

index 7e4922d..442669e 100644

--- a/LICENSE

+++ b/LICENSE

 @@ -1,4 +1,4 @@

-Copyright (c) 2012 Envy Labs LLC

+Copyright (c) 2012 Code School LLC

edit

Show unstaged differences since last commit

Line removed 

Line added 

(28)

V I E W I N G S T A G E D D I F F E R E N C E S

$ git add LICENSE

$ git diff

$

No differences, since all changes are staged 

 git diff --staged

 View staged differences

 diff --git a/LICENSE b/LICENSE

index 7e4922d..442669e 100644

--- a/LICENSE

+++ b/LICENSE

 @@ -1,4 +1,4 @@

-Copyright (c) 2012 Envy Labs LLC

+Copyright (c) 2012 Code School LLC

(29)

# On branch master

# Changes to be committed:

#

(use "git reset HEAD <file>..." to unstage)

#

# modified:

LICENSE

#

HEAD

U N S T A G I N G F I L E S

$ git status

$

Unstage Tip

 git reset HEAD LICENSE

Refers to last commit

Unstaged changes after reset:

M LICENSE

(30)

D I S C A R D C H A N G E S

$

Blow away all changes

since last commit

 git status

$ git checkout -- LICENSE

# On branch master

# Changed but not updated:

# (use "git add <file>..." to update what will be committed)

# (use "git checkout -- <file>..." to discard changes in working directory) #

# modified: LICENSE #

$ git status

(31)

HEAD

S K I P S T A G I N G A N D C O M M I T

Readme.txt

here is my readme  and now I can sleep

Readme.txt

edit

Add changes from all tracked files

Doesn’t add new (untracked) files

here is my readme the cake is a lie

$ git commit -a -m "Modify readme"

[master d00fefc] Modify readme

 1 files changed, 1 insertions(+), 1 deletions(-)

(32)

U N D O I N G A C O M M I T

# On branch master

# Changes to be committed:

#

(use "git reset HEAD <file>..." to unstage)

#

# modified:

README.txt

#

$ git reset --soft HEAD^

 git status

$

Reset into staging

Move to commit before ‘HEAD’

Now I can make changes, and re-commit

Whoops, we forgot something on that commit.

master 

(33)

A D D I N G T O A C O M M I T

[master fe98ef9] Modify readme and add todo.txt.

 2 files changed, 2 insertions(+), 1 deletions(-)

 create mode 100644 todo.txt

$ git add todo.txt

$

Add to the last commit

New commit message

Maybe we forgot to add a

!

le

 git commit --amend -m "Modify readme & add todo.txt."

Whatever has been staged is added to last commit

master 

(34)

U S E F U L C O M M A N D S

$ git reset --soft HEAD^

Undo last commit, put changes into staging

 git reset --hard HEAD^

Undo last commit and all changes

$

 git commit --amend -m "New Message"

Change the last commit

$

 git reset --hard HEAD^^

Undo last 2 commits and all changes

$

(35)

H O W T O S H A R E ?

Git doesn’t take care of access control

“git remote” command

 p us h

p u l l

p u l l 

Remote Repository

(36)

R E M O T E R E P O S I T O R Y H O S T I N G

GitHub

BitBucket

• Gitosis

• Gitorious

Hosted

Self Managed

 p us h

master

(37)
(38)
(39)

A D D I N G A R E M O T E

New remote

our name for this remote

address

$ git remote add origin https://github.com/Gregg/git-real.git

$ git remote -v

 origin https://github.com/Gregg/git-real.git (fetch)

 origin https://github.com/Gregg/git-real.git (push)

show remote repositories

(40)

P U S H I N G T O R E M O T E

$ git push -u origin master

remote repository name

local branch to push

Username for 'https://github.com': Gregg

Password for 'https://[email protected]':  Counting objects: 11, done.

Delta compression using up to 4 threads.  Compressing objects: 100% (6/6), done.

 Writing objects: 100% (11/11), 1.50 KiB, done. Total 11 (delta 0), reused 0 (delta 0)

To https://github.com/Gregg/git-real.git * [new branch] master -> master

https://help.github.com/articles/set-up-git

Password caching

 p us h

master

(41)
(42)
(43)

P U L L I N G F R O M R E M O T E

$ git pull

remote: Counting objects: 5, done.

remote: Compressing objects: 100% (1/1), done.

remote: Total 3 (delta 1), reused 3 (delta 1)

Unpacking objects: 100% (3/3), done.

From https://github.com/Gregg/git-real

 

fe98ef9..4e67ded

master

-> origin/master

Updating fe98ef9..4e67ded

Fast-forw

 ard

todo.txt | 1 +

 1 file changed, 1 insertion(+)

To pull changes down from the remote

 p u l l

 origin

 I t ’s g o od t o

d o t h is o f t

e n

(44)

H A V I N G M U L T I P L E R E M O T E S

 origin

production

(45)

W O R K I N G W I T H R E M O T E S

$  git remote add <name> <address>

$  git remote rm <name>

To add new remotes

To remove remotes

$  git push -u <name> <branch>

To push to remotes

(46)

H E R O K U R E M O T E

$ heroku create

$ git push heroku master

 Creating dev-server-1426... done, stack is cedar

http://dev-server-1426.herokuapp.com/ | [email protected]: dev-server-1426.git  Git remote heroku added

 git repo ssh address

triggers deploy

$  git remote -v

heroku [email protected]: dev-server-1426.git (fetch) heroku [email protected]: dev-server-1426.git (push)  origin https://github.com/Gregg/git-real.git (fetch)  origin https://github.com/Gregg/git-real.git (push)

(47)

U S E F U L C O M M A N D S

$ git reset --soft HEAD^

Don’t d o these af ter  you push

 git reset --hard HEAD^

$

 git commit --amend -m "New Message"

$

 git reset --hard HEAD^^

$

(48)
(49)
(50)

L E V E L 3

(51)

C O L L A B O R A T I N G

C O L L A B O R A T I N G

push

push

github

github

How do we start collaborating?

How do we start collaborating?

a

a

n

n

e

e

 G

 G

 r

 r

 e

 e

 g

 g

 g

 g

“I want a copy”

“I want a copy”

“Clone the repo!”

“Clone the repo!”

local repo local repo

?

(52)

F I N D I N G T H E R E P O U R L

(53)

F I N D I N G T H E R E P O U R L

(54)

C L O N I N G A R E P O S I T O R Y

$ git clone https://github.com/codeschool/git-real.git

 Cloning into '

 git-real

'...

URL of the remote repository

$ git clone https://github.com/codeschool/git-real.git

 git-demo

 Cloning into '

 git-demo

'...

(55)

 origin https://github.com/codeschool/git-real.git (fetch)

 origin https://github.com/codeschool/git-real.git (push)

G I T C L O N E

HEAD

master 

1

- Downloads the entire repository into a new git-real directory.

2

- Adds the ‘origin’ remote, pointing it to the clone URL.

3

- Checks out initial branch (likely master).

$ git remote -v

(56)

Need to work on a feature that will take some time?

B R A N C H I N G O U T

master 

cat

branch created from master 

J ane

$ git branch

 cat

HEAD

$ git branch

cat

* master

HEAD still on master 

(57)

S W I T C H I N G T O A B R A N C H

HEAD

Time to jump on that new 'cat' branch.

HEAD is now on ‘cat’

master 

$ git checkout

 cat

Switched to branch 'cat'

cat

(58)

master 

cat

W O R K I N G O N A B R A N C H

HEAD

committed to the

“cat” branch

$ echo "Schrödinger" > cat.txt

$ git add

 cat.txt

$ git commit -m

"Create quantum cat."

[cat ab48a3f] Create quantum cat.

 1 file changed, 1 insertion(+)

 create mode 100644 cat.txt

(59)

README.txt cat.txt

master 

cat

W O R K I N G O N A B R A N C H

HEAD

$ ls

(60)

commit 1191ceb7252c9d4b1e05c9969a55766a8adfce3b

 Author: Gregg <[email protected]>

Date:

Wed Jun 27 23:11:20 2012 -0700

Add README.

master 

cat

B A C K T O M A S T E R

$ git checkout

master

HEAD

and we’re back on master 

cat.txt is gone!

$ git log

 nothing in the log either 

Switched to branch 'master'

$ ls

References

Related documents

toda: Dorylaimida ) from the rhizosphere of the wild growing grape ( Vitis vinifera ssp. silvestris ) in the riparian woods of the rivers Danube and March

Silicon Valley San Francisco San Francisco Peninsula Austin Seattle Raleigh-Durham Salt Lake City Denver Boston Baltimore New York Washington DC San Diego Pittsburgh

The calculated values of V can now be compared to the measured values defined in Table 1 at the specific time the measurements are available, considering the calculated values

6 the distribution of possible food security outcomes for pastoralist regions based on this combination of rainfall and forecast is noticeably different for forecasts of

[3] NEST’s primary goals are to read in ESA and third part SAR data products, provide tools for calibration, orthorectification, co-registration, interferometry,

— Sutural angle of elytra without small tooth; head, antennae, scutellum, legs, and venter (except abdominal sterna laterally) black; pronotum yellow with disc black from base to

This paper proposes a logical model to examine the effect of the EDoS attack in cloud environment using finite queuing model and enhanced with experimental model. Due to