+ All Categories
Home > Documents > Git - A fast distributed revision control system › lehre › ... · A fast distributed revision...

Git - A fast distributed revision control system › lehre › ... · A fast distributed revision...

Date post: 26-Jun-2020
Category:
Upload: others
View: 7 times
Download: 0 times
Share this document with a friend
24
Outline The three W’s Overview of gits structure Using git Final stuff Git A fast distributed revision control system Nils Mosch ¨ uring PhD Student (LMU) Nils Mosch ¨ uring PhD Student (LMU) , Git 1
Transcript
Page 1: Git - A fast distributed revision control system › lehre › ... · A fast distributed revision control system ... What is a version control system? A system which monitors data

Outline The three W’s Overview of gits structure Using git Final stuff

GitA fast distributed revision control system

Nils MoschuringPhD Student (LMU)

Nils Moschuring PhD Student (LMU) , Git 1

Page 2: Git - A fast distributed revision control system › lehre › ... · A fast distributed revision control system ... What is a version control system? A system which monitors data

Outline The three W’s Overview of gits structure Using git Final stuff

1 The three W’sWhat?Why?Workflow and nomenclature

2 Overview of gits structureStructureBranches

3 Using gitSetting upWorkingSharing

4 Final stuff

Nils Moschuring PhD Student (LMU) , Git 2

Page 3: Git - A fast distributed revision control system › lehre › ... · A fast distributed revision control system ... What is a version control system? A system which monitors data

Outline The three W’s Overview of gits structure Using git Final stuff

What is a version control system?

A system which monitors data continuously

’Monitors‘ means that it will detect any changes to the data and will beable to tell you about them.

At every point during your work you can tell the system to take a snapshot(a record of the current status of the data).

You can let others change your data and these changes will also berecorded.

A friend with benefits (on top of the above)

Everything is saved with a timestamp and user information (making it easyto pinpoint and blame the source of a mistake).

All changes can easily be reverted to any previous state.

You can even revert to a previous version, fix an error and automaticallyredo all the other good stuff!

Nils Moschuring PhD Student (LMU) , Git 4

Page 4: Git - A fast distributed revision control system › lehre › ... · A fast distributed revision control system ... What is a version control system? A system which monitors data

Outline The three W’s Overview of gits structure Using git Final stuff

Why do I need it?

Single User:

This functionality greatly simplifies the development process of digitalproducts.

Especially the development of software.

Multi User:

Everybody can change whatever he wants, without consulting anybodyelse.

All the modifications by all the different users will be merged to one finalresult automatically.

If they don’t overlap.

Different branches are supported.They enable you to work on a specificsubproblem separately. Of course, these can later be merged withouttrouble.

If they don’t overlap.

Nils Moschuring PhD Student (LMU) , Git 5

Page 5: Git - A fast distributed revision control system › lehre › ... · A fast distributed revision control system ... What is a version control system? A system which monitors data

Outline The three W’s Overview of gits structure Using git Final stuff

Workflow - Commit

Nils Moschuring PhD Student (LMU) , Git 6

Page 6: Git - A fast distributed revision control system › lehre › ... · A fast distributed revision control system ... What is a version control system? A system which monitors data

Outline The three W’s Overview of gits structure Using git Final stuff

Workflow - Commit

Nils Moschuring PhD Student (LMU) , Git 7

Page 7: Git - A fast distributed revision control system › lehre › ... · A fast distributed revision control system ... What is a version control system? A system which monitors data

Outline The three W’s Overview of gits structure Using git Final stuff

Workflow - Checkout

Nils Moschuring PhD Student (LMU) , Git 8

Page 8: Git - A fast distributed revision control system › lehre › ... · A fast distributed revision control system ... What is a version control system? A system which monitors data

Outline The three W’s Overview of gits structure Using git Final stuff

Workflow - Merge

Nils Moschuring PhD Student (LMU) , Git 9

Page 9: Git - A fast distributed revision control system › lehre › ... · A fast distributed revision control system ... What is a version control system? A system which monitors data

Outline The three W’s Overview of gits structure Using git Final stuff

Workflow - Branches

Nils Moschuring PhD Student (LMU) , Git 10

Page 10: Git - A fast distributed revision control system › lehre › ... · A fast distributed revision control system ... What is a version control system? A system which monitors data

Outline The three W’s Overview of gits structure Using git Final stuff

Git is a distributed RCS

Nils Moschuring PhD Student (LMU) , Git 12

Page 11: Git - A fast distributed revision control system › lehre › ... · A fast distributed revision control system ... What is a version control system? A system which monitors data

Outline The three W’s Overview of gits structure Using git Final stuff

Working Copy - Index - Repository

WorkingDirectory Index Repository

addcheckout commitreset

Nils Moschuring PhD Student (LMU) , Git 13

Page 12: Git - A fast distributed revision control system › lehre › ... · A fast distributed revision control system ... What is a version control system? A system which monitors data

Outline The three W’s Overview of gits structure Using git Final stuff

Branches

How do they work?

different versions of the same overall functionality (overlaps)

experimental stuff, tryouts

parallel development on the same trunk

What branches do I have and why:

Run git branch -a

Git keeps copies of all branches on your source repository marked with aremotes/ prefix. If you run the git fetch command, these local copies will beupdated. git fetch makes changes from a different repository available in yourrepository.

You can create new remotes with the git remote command. You can set an alias(as ‘origin’ in the cloned case).

The branches marked as remotes/ can not be checked out. You have to create alocal branch which tracks the remote one.

‘Tracking’ means, that git pull and git push will use these branches as adefault.

Nils Moschuring PhD Student (LMU) , Git 14

Page 13: Git - A fast distributed revision control system › lehre › ... · A fast distributed revision control system ... What is a version control system? A system which monitors data

Outline The three W’s Overview of gits structure Using git Final stuff

Branches - workflow example:new features & multi users

V1 V2

V2

V4

V1 V3

V5V3

merge mergebranch

Master

Testing

commits

Nils Moschuring PhD Student (LMU) , Git 15

Page 14: Git - A fast distributed revision control system › lehre › ... · A fast distributed revision control system ... What is a version control system? A system which monitors data

Outline The three W’s Overview of gits structure Using git Final stuff

Branches - workflow example:different versions

V1 V2

V2

V4

V1 V3

V5V3

mergebranch

oven

microwave

V2V1grill

branch merge

V3

Nils Moschuring PhD Student (LMU) , Git 16

Page 15: Git - A fast distributed revision control system › lehre › ... · A fast distributed revision control system ... What is a version control system? A system which monitors data

Outline The three W’s Overview of gits structure Using git Final stuff

Using git: Setting up

Configuring Git

Run:

git config --global user.name "Bob"

git config --global user.email "[email protected]"

Setting up a local repository

git init

Copying (Cloning) an existing repository

git clone GIT-URL

Possible GIT-URLs (only ssh and local shown):ssh://[user@]host.xz[:port]/path/to/repo.git/[user@]host.xz:path/to/repo.git//path/to/repo.git/

Nils Moschuring PhD Student (LMU) , Git 18

Page 16: Git - A fast distributed revision control system › lehre › ... · A fast distributed revision control system ... What is a version control system? A system which monitors data

Outline The three W’s Overview of gits structure Using git Final stuff

Using git: working

The git checkout command

Checks out a branch: Sets your repository to the last commit of the branch(called the HEAD), sets your index and your working directory to thedesired branch data.Important Command line argument:

-b Create a new branch and switch to it

The git add command

Puts local changes into the index on a file by file basis.

The git diff command

Shows the difference between your working copy and the index.

The git status command

Shows the current status of your working directory, index and repository.

Nils Moschuring PhD Student (LMU) , Git 19

Page 17: Git - A fast distributed revision control system › lehre › ... · A fast distributed revision control system ... What is a version control system? A system which monitors data

Outline The three W’s Overview of gits structure Using git Final stuff

Using git: working

The git commit command

Puts the changes in the index into the repository creating a newcheckpoint (commit).Important command line argument:

-a Includes adding all changes to the index.-m Followed by a string (use quotes!); Sets this string as the commit message.

The git branch command

Creates a new branch or shows the existing branches.Important command line arguments:

-a Shows all existing branches-d Deletes a branch (verifying that the changes are in the current branch)-D Delete a branch without verifications

Example: git branch my_testing remotes/origin/testingCreates a new local branch named ‘my testing’ which is tracking thebranch named ‘testing’ on the origin repository.

Nils Moschuring PhD Student (LMU) , Git 20

Page 18: Git - A fast distributed revision control system › lehre › ... · A fast distributed revision control system ... What is a version control system? A system which monitors data

Outline The three W’s Overview of gits structure Using git Final stuff

Using git: working

The git merge command

Normally you will use it to merge a branch you will abandon back into yourmain branch. To do that, checkout the main branch and dogit merge soon-to-be-abandoned-branch

If there are conflicts (the two branches differ in the same line), git willleave conflict markers. They look like this:

<<<<<<< masterContent of line x in branch master=======Content of line x in branch local>>>>>>> local

Resolve them and commit the result!

The gitk command

This will show a nice graphical representation of your repository, the branchesand their relations. A good alternative for Mac OS X is GitX which can be foundon MacPorts.

Nils Moschuring PhD Student (LMU) , Git 21

Page 19: Git - A fast distributed revision control system › lehre › ... · A fast distributed revision control system ... What is a version control system? A system which monitors data

Outline The three W’s Overview of gits structure Using git Final stuff

Using git: sharing

The git pull command

Consists of the git fetch and the git merge command as follows

The first parameter can be a repository GIT URL. It is used to fetch from.The results are normally stored in the local ‘remotes/remote-alias/’branches.

The second parameter is the branch on the foreign repository to be usedin the merge command.

If you’ve set up your tracking branches, git will automatically know all ofthe above and a git pull without any arguments updates your localbranch to the respective branch on the remote repository.

This command always modifies the currently checked out branch!

Of course this could cause merge conflicts...

Nils Moschuring PhD Student (LMU) , Git 22

Page 20: Git - A fast distributed revision control system › lehre › ... · A fast distributed revision control system ... What is a version control system? A system which monitors data

Outline The three W’s Overview of gits structure Using git Final stuff

Using git: sharing

The git push command

Tries to update a branch on a remote repository.

Normally works only for fast forwards, i.e. merges with no conflicts (thereare good reasons)

You can force a push, but if you do, it will NOT do a merge!

If the push doesn’t work, the normal procedure would be to do a pull first,resolve the problems and then push the new commit, which is thendirectly descendent from the current status on the repository.

Nice feature: hooksYou can make interesting things happen to a repository every

time you push into it... -http://www.kernel.org/pub/software/scm/git/docs/git-push.html

Nils Moschuring PhD Student (LMU) , Git 23

Page 21: Git - A fast distributed revision control system › lehre › ... · A fast distributed revision control system ... What is a version control system? A system which monitors data

Outline The three W’s Overview of gits structure Using git Final stuff

Using git: advanced git commands

The git rebase command

Rewriting of history

Squashing of commits

Creating a linear history

The git grep command

Improved searching in repositories

Follows the same basic syntax as Unix grep

The git stash command

Puts your changes to a safe place and resets the working directory andindex

Handy for quick looks into different branches without having to create acommit

Nils Moschuring PhD Student (LMU) , Git 24

Page 22: Git - A fast distributed revision control system › lehre › ... · A fast distributed revision control system ... What is a version control system? A system which monitors data

Outline The three W’s Overview of gits structure Using git Final stuff

Using git: advanced git commands, rebase

V1 V2

V2

V4

V1 V3

V3

mergebranch

Master

Testing

V1 V2 V2V4 V1 V3V3

rebase

Nils Moschuring PhD Student (LMU) , Git 25

Page 23: Git - A fast distributed revision control system › lehre › ... · A fast distributed revision control system ... What is a version control system? A system which monitors data

Outline The three W’s Overview of gits structure Using git Final stuff

Using git: advanced git commands

The git rebase command

Rewriting of history

Squashing of commits

Creating a linear history

The git grep command

Improved searching in repositories

Follows the same basic syntax as Unix grep

The git stash command

Puts your changes to a safe place and resets the working directory andindex

Handy for quick looks into different branches without having to create acommit

Nils Moschuring PhD Student (LMU) , Git 26

Page 24: Git - A fast distributed revision control system › lehre › ... · A fast distributed revision control system ... What is a version control system? A system which monitors data

Outline The three W’s Overview of gits structure Using git Final stuff

Final stuff

Of course there are many more really useful commands you should use,please discover them on your own. References I used:

http://book.git-scm.com/index.html

http://www.kernel.org/pub/software/scm/git/docs/git.html

Take-Home-Message

USE GIT

Nils Moschuring PhD Student (LMU) , Git 28


Recommended