58
Words in CAPS, <angle> or italics usually means they need to be substituted with something SOURCE, DEST need to be pathnames to files Words or options enclosed in [ ] are optional A | separating words indicates that they are mutually exclusive [-r|-s] -r and -s are both optional but only one can be used at a time An ellipsis following means more than one can be specified SOURCEmeans one or more source files Basic Commands Man Pages 1

SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

● Words in CAPS, <angle> or italics usually means they need to be substituted with something

● SOURCE, DEST need to be pathnames to files● Words or options enclosed in [ ] are optional● A | separating words indicates that they are mutually

exclusive○ [-r|-s]

-r and -s are both optional but only one can be used at a time

● An ellipsis … following means more than one can be specified○ SOURCE… means one or more source files

Basic Commands

Man Pages

1

Page 2: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

● Relative pathnames do not begin with a /○ Are relative to the Current Working Directory

● Absolute pathnames always begin with /○ Or relative to the root directory (/)

● All (even empty) directories have two special subdirectories○ . is the directory itself○ .. is the parent of that directory

$ pwd/home/ebasheer

$ cd Documents$ pwd/home/ebasheer/Documents

$ cd ..$ pwd/home/ebasheer

Pathnames

Relative and

AbsolutePathnames

2

Page 3: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

● pwdPrint current working directory to stdout

● cdChange the current working directory

● mkdirCreate a directory

● cpCopy files and directories

● mvMove/rename files

● rmRemove/Delete files or directories

Essential Commands

Examples

3

Page 4: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

chmodChange file mode

● Example Output of ls -l

$ ls -ltotal 20drwxrwxr-x 8 ebasheer ebasheer 4096 Aug 16 22:49 centraldrwxrwxr-x 7 ebasheer ebasheer 4096 Aug 16 21:49 central.bak-rwxrwxr-- 1 ebasheer ebasheer 0 Aug 23 21:40 convert.sh-rw-rw-r-- 1 ebasheer ebasheer 0 Aug 23 21:39 inputexample.txtdrwxrwxr-x 3 ebasheer ebasheer 4096 Aug 16 22:47 myprojectdrwxrwxr-x 3 ebasheer ebasheer 4096 Aug 16 22:43 myprojectclonedrwxrwxr-x 2 ebasheer ebasheer 4096 Aug 23 17:13 tmpdir

File Permission

Bits

4

Page 5: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

-rwxrw-r--user group other

File Permission

Bits$ chmod u-rx script.sh$ ls -ltotal 0--w-rwx--x 1 ebasheer ebasheer 0 Aug 23 20:46 script.sh

$ cat script.sh cat: script.sh: Permission denied

$ chmod u+rx,g-w,o+r script.sh $ ls -l script.sh -rwxr--r-- 1 ebasheer ebasheer 0 Aug 31 11:24 script.sh

5

Page 6: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

● echo Write a line of text to stdout

● catPrint contents of file to stdout

● findSearch for files

● lessA “pager”. Text file viewer with scrolling and search

● gzip, gunzipCompress/Uncompress files

Essential Commands

Examples

6

Page 7: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

● sortSort lines of text files

● uniq Remove repeated lines

● wcPrint line, word, byte counts

● head, tailPrint first/last lines of a file

● grepPrint lines in a file that match a pattern

Essential Commands

Examples

7

Page 8: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

Unix Toolbox Philosophy

8

Page 9: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

The Unix Toolbox PhilosophySee info coreutils

* Output of entire files:: cat tac nl od base32 base64* Formatting file contents:: fmt pr fold* Output of parts of files:: head tail split csplit* Summarizing files:: wc sum cksum md5sum sha1sum sha2* Operating on sorted files:: sort shuf uniq comm ptx tsort* Operating on fields:: cut paste join* Operating on characters:: tr expand unexpand* Directory listing:: ls dir vdir dircolors* Basic operations:: cp dd install mv rm shred* Special file types:: mkdir rmdir unlink mkfifo mknod ln link readlink* Changing file attributes:: chgrp chmod chown touch* Disk usage:: df du stat sync truncate* Printing text:: echo printf yes* Conditions:: false true test expr* Redirection:: tee* File name manipulation:: dirname basename pathchk mktemp realpath* Working context:: pwd stty printenv tty* User information:: id logname whoami groups users who* System context:: date arch nproc uname hostname hostid uptime* SELinux context:: chcon runcon* Modified command invocation:: chroot env nice nohup stdbuf timeout* Process control:: kill* Delaying:: sleep* Numeric operations:: factor numfmt seq

Unix Toolbox

9

Page 10: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

PipesThe | character connects two commands in the shell

● cmd1 | cmd2Connects stdout of cmd1 to stdin of cmd2

● Many commands accept input from stdin by default● Using cat, sort and uniq in a pipeline

Shell

10

Page 11: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

# Examples$ cat cities.txt | sort | uniq$ cat cities.txt | nl | sort -sk2 | uniq -f1 | sort -nk1 | cut -f2$ cat randint.txt |grep '2$'|wc -l

Shell

Pipes

11

Page 12: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

RedirectionRedirect a standard stream to/from a file

● cmd1 > file.txtRedirects stdout of cmd1 to file.txt

● To write the output of our pipeline to a file

$ cat cities.txt | sort | uniq > uniqcities.txt

Shell

Redirection● cmd1 < file.txt

Redirects file.txt to stdin of cmd1

$ sort < cities.txt$ sort < cities.txt | uniq$ sort cities.txt | uniq

12

Page 13: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

Editing Text Files

13

Page 14: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

Text Editors

● Terminal○ Vim

○ Emacs

○ Nano

○ Pico

...

● GUI○ Gedit

○ Kate

...

Editing Text Files

14

Page 15: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

Vim

● Vim is a modal editorCommand and text input mode

● Command mode: default mode when vim starts○ Movement with h, k, j, l (or arrow keys)○ Other key perform various functions. e.g

■ Delete a line, character or worddd, x, dw

■ Copy a line, character or word to a register (clipboard)yy, yl, “ayw

■ PasteP, p

■ Undo, Redou , Ctrl-r

■ Combination of commands or commands repeated a number of times

Editing Text Files

15

Page 16: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

Vim

● Input mode■ i, a, o enter insert mode■ Esc to return to command mode

Editing Text Files

16

Page 17: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

Vim

Ex commandsBegin with a colon :

● Save file:w in command mode

● Quit Vim:q in command mode

● Quit discarding modifications:q! In command mode

type vimtutor on command lineand follow the tutorial

Editing Text Files

17

Page 18: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

Introduction to Linux

● Chapters 2, 3, 5, 6

Linux

Reading

18

Page 19: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

Introduction to git

19

Page 20: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

git

Why Version Control

Scenario

Begin a project with test.py

Make changes to the filetest a new feature for example

But want to keep the older versionso that we can revert to it if we need to

Version numbers added as the project progresses and collaborators joinAt each step a copy is made to keep history

projects

test.py

test_orig.py

20

Page 21: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

projects

pyproj.py

pyproj_orig.py

bob

alice

pyproj.py

pyproj_orig.py

pyproj_v1.py

pyproj_v2.py

pyproj_v1.1.py

pyproj_v1.py

pyproj_v2.py

pyproj_v2_merged_bob_v1_bugfix.py

pyproj_release_08_2016.pyQuickly becomes hard to manage

And easy to make mistakes

21

Page 22: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

Version Control Systems

22

Page 23: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

Version Control

Systems

Basic Function

● Maintain a history of changes to files● Allow retrieval of any previous revision● Each change is recorded along with information that

allows us to answer the questions○ When was the change made○ Who made the change

● Serves as documentation of progress

23

Page 24: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

Version Control

Systems

Well KnownTools

CVSSVN (subversion)gitMercurialBazaarLibreSource...

gitgit is a VCS created and developed by Linus Torvalds and the Linux kernel community as an alternative to a proprietary system they were using until 2005

● Distributed Development● Built-in integrity● Fast● Free and Open Source

24

Page 25: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

$ git config --global user.name "Ershaad Basheer"$ git config --global user.email [email protected]

git

Getting Started

One-timeSetup

Setting your identity

Choosing an editor

$ git config --global core.editor vim

Viewing settings

$ git config --list

25

Page 26: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

git

Getting Help

help commandgit help <command>

$ git help config$ git help commit

man pagesman git-<command>

$ man git-config$ man git-commit

26

Page 27: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

commitc4af9f8840

commitde709eb553

commit8ef5605f384

commit1b1c2c5ac

git

Terminology

A

B

C

D

TIME

A

B

C

D

A

B

C

D

A

B

C

D

project project project project

● Commit○ Snapshot of what the entire project looked like at a point in time

● Repository○ All the files that are under version control and the complete history of

commits

27

Page 28: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

git

Working with git

● Initializing a Repository○ In an directory○ Empty directory in our example

~/work/report$ git init

● git shows that no files are being tracked

~/work/report$ git status$ git statusOn branch master

Initial commit

nothing to commit (create/copy files and use "git add" to track)

28

Page 29: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

git

Working with git

$ lsexpenses.csv

● We can create or copy files

$ git statusOn branch master

Initial commit

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

expenses.csv

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

● git indicates that there are untracked files

29

Page 30: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

git

Working with git

● We add the files to the index○ Required step before tracking changes to a new file

~/work/report$ git add expense.csv

● Git now shows us that a new file has been added to the index

$ git statusOn branch master

Initial commit

Changes to be committed: (use "git rm --cached <file>..." to unstage)

new file: expenses.csv

30

Page 31: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

git

Working with git

● We still do not have any snapshots in our history

~/work/report$ git logfatal: your current branch 'master' does not have any commits yet

● We create our first commit

~/work/report$ git commit -m "initial commit"[master (root-commit) 05751d1] initial commit 2 files changed, 7 insertions(+) create mode 100644 expense1.csv create mode 100644 expense2.csv

31

Page 32: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

git

Working with git

● Since we haven’t edited any files since the last commit○ git status has nothing interesting to output

$ git statusOn branch masternothing to commit, working directory clean

● And our repository now has one commit○ Copy of the state of files in our project saved in history

~/work/report$ git logcommit d8f0fcfda2d09d437cdbd339db11cf8b6365508fAuthor: Ershaad Basheer <[email protected]>Date: Tue Aug 9 12:46:15 2016 -0400

initial commit

commitc4af9f8840

A

B

C

D

project

32

Page 33: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

git

Working with git

● After editing one of the files○ Make changes using a text editor○ Or any other program (Like a word processor, etc)○ Git doesn’t care how the file is edited

● Git shows that one of the files has been modified

~/work/report$ git statusOn branch masterChanges 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: expenses.csv

no changes added to commit (use "git add" and/or "git commit -a")

● Before we can commit the changed file to the repository○ We need to add it to the index. or stage the changed file

33

Page 34: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

git

Staging a File

● The modified file now exists in the “Working Directory”

Working Directory

Index

M

Repository

34

Page 35: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

git

Staging a File

● To view the differences between what’s in the working directory and the index

Working Directory

Index

M

Repository

~/work/report$ git diff expenses.csvdiff --git a/expenses.csv b/expenses.csvindex 1885f91..29f8e17 100644--- a/expenses.csv+++ b/expenses.csv@@ -1,4 +1,4 @@ CATEGORY,BUDGET,CURRENT-Groceries,1000,150+Groceries,1001,150 Electric,100,66 Utilities,250,25

Δ

35

Page 36: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

git

Staging a File

● We use git add once again to stage the file

~/work/report$ git add expenses.csvWorking DirectoryM

Repository

IndexM● Now the modified file exists

both in the working directory and the Index

36

Page 37: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

git

Staging a File

● Git tells us that the working directory and the index are identical

~/work/report$ git statusOn branch masterChanges to be committed: (use "git reset HEAD <file>..." to unstage)

modified: expenses.csv

Working DirectoryM

Repository

IndexM

● But, they differ from the last commit in the repository

37

Page 38: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

git

Staging a File

● To view the differences between what’s in the index and the last commit

~/work/report$ git diff --stageddiff --git a/expenses.csv b/expenses.csvindex 1885f91..29f8e17 100644--- a/expenses.csv+++ b/expenses.csv@@ -1,4 +1,4 @@ CATEGORY,BUDGET,CURRENT-Groceries,1000,150+Groceries,1001,150 Electric,100,66 Utilities,250,25

Δ

Working DirectoryM

Repository

IndexM

38

Page 39: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

git

Commit

● When we’re satisfied with what is in the index○ We’re ready to make a commit

~/work/report$ git commit -m "Update grocery\ budget"[master cbbb2de] Update grocery budget 1 file changed, 1 insertion(+), 1 deletion(-)

Working Directory

Index

Repository● Takes what is in the index and

permanently stores it in the repository as a commit

39

Page 40: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

git

Commit

● Working directory, index and last commit have the same content

$ git statusOn branch masternothing to commit, working directory clean

Working Directory

Index

Repository

40

Page 41: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

git

Commit History

● We now have two snapshots of our project in the repository○ Each identified by a commit hash

● At all times, we only see two files in our working directory○ Git takes care of all the moving around of data to maintain revision

history behind the scenes

~/work/report$ git logcommit cbbb2de252199245c4dc07b51d247ff90f997e4cAuthor: Ershaad Basheer <[email protected]>Date: Wed Aug 31 17:10:36 2016 -0400

Update grocery budget

commit e884dd46443fed2fb22b101e8b373f23ee45e093Author: Ershaad Basheer <[email protected]>Date: Wed Aug 31 16:56:12 2016 -0400

initial commit

41

Page 42: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

git

Undoing things

● Unstaging a file○ You staged a file for commit but

changed your mind

~/work/report$ git reset HEAD expenses.csv Working Directory

Index

Repository

● Takes the version of the file in ref HEAD which is the last commit and copies it into the index

● Now the index is identical to the last commit

42

Page 43: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

git

Undoing things

● Discarding modifications in the working directory○ Overwriting files in the working

directory is dangerous○ Cannot be undone

~/work/report$ git checkout expenses.csv

Working Directory

Index

Repository

43

Page 44: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

git

Undoing things

● Reverting to a version of a file from a previous commit○ Copies the file from the commit to

the index○ And the working directory

~/work/report$ git checkout e884dd46 expenses.csv

Working Directory

Index

Repository

44

Page 45: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

Collaboration in git

45

Page 46: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

git

Collaboration in git

● git is a distributed version control system by design● Collaborators work on a local copy of a repository

46

Page 47: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

git

Collaboration in git

● Local repositories begin as a “clone” of another local repository

Repository userA

Repository userB

git clone

47

Page 48: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

git

Collaboration in git

● Collaborators work on a local copy of a repository○ Make changes and commit them to this local repository

■ Building a local history of commits

Repository userA

Repository userB

48

Page 49: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

git

Simple Workflow

● One repository is designated as the “central” repository○ Could be on a web-based Git repository hosting service like GitHub or

Bitbucket

Central Repository

49

Page 50: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

git

Cloning

● Developers begin by cloning the central repository● When cloning, git includes a reference to the “parent”

repository called origin

Central Repository

Repository Repository Repository

git clone git clone git clone

John Mary

50

Page 51: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

git

Local repositories

● Developers edit files and commit changes to their local repository○ Oblivious to what other are doing in their repositories,○ Or the central repository○ Until they decide to synchronize upstream

Central Repository

git statusgit addgit commit

git statusgit addgit commit

git statusgit addgit commit

John Mary

51

Page 52: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

git

Pushing to the Central

Repository

● This is done with agit push

Central Repository

Mary

git push origin master

John

52

Page 53: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

git

Pushing to the Central

Repository

● Git detects that the central repository hasn’t changed since John cloned it, so

● Commits can be directly merged into the central repository

Central Repository

Mary

Central Repository

git push origin master

John

53

Page 54: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

git

Pushing to the Central

Repository

● Now, developer Mary decides it’s time to push her changes to the project

● But this will fail

Central Repository

John

git push origin master

Mary

54

Page 55: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

git

Pushing to the Central

Repository

● Git determines that the central repository has changed since it was cloned

● And the commit histories therefore diverge● Git refuses to merge changes into the central repository

Central Repository

John

git push origin master

Mary

55

Page 56: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

git

Pulling changes

● Before pushing commits● Upstream commits in the central repository need to be

merged into the local repository withgit pull. Creates a “merge commit”

● Can raise a merge conflict

Central Repository

git pull origin masterMary Mary

M

56

Page 57: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

git

Pushing to the Central

Repository

● Now that the commit history of the central repository has been merged locally

● Mary will be ready to push her commits

Central Repository

git push origin master

Central Repository

Mary

M

M

57

Page 58: SOURCE, DEST to be substituted with something Words or ... · The Unix Toolbox Philosophy See info coreutils * Output of entire files:: cat tac nl od base32 base64 * Formatting file

git

Reading

Git Book

● Chapters 1 and 2

58